20110601
来源:互联网 发布:linux建立用户 编辑:程序博客网 时间:2024/05/25 01:36
查看程序运行后的返回值
Unix echo $?
Windows echo%ERRORLEVEL%
文件结束符的输入
Unix control+d
Windows control+z
因常量定义后不能修改,所以定义时必须初始化
const int i = 10;
const引用是指向const的引用
非const引用只能绑定到与该引用同类型的对象。
const应用可以绑定到不同但相关的类型的对象或绑定到右值。
string库
string的size()返回的是string::size_type类型,是一个类似于unsignedint的类型。
对string对象的单个字符的处理需要使用cctype中定义的函数。
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main(int argc, char*argv[])
{
string s("HelloWorld!!!");
string::size_type punct_cnt = 0;
for(string::size_type index = 0; index != s.size(); ++index)
{
if(ispunct(s[index]))
++punct_cnt;
}
cout << punct_cnt << " puctuation characters in " << s<< endl;
return 0;
}