C++初学者小细节(不定时更新)

A:如何在头文件中定义string类型?

B:string是标准库std里的一种数据类型,所以必须先用using namespace再定义string数据类型

  例如:

 1 //string.h
 2 
 3 std::string a("Hello world!");
 4 std::cout << a << endl;
 5 
 6 //或者
 7 
 8 using namespace std;
 9 string a("Hello world!");
10 cout << a << endl;

 -------------------------------------------------------------- --------------------------------------------------------------

 

A:使用cin流或者while(cin>>变量)终止后,出现cin不能再输入而直接跳过

B:使用

 

1 cin.clear();//重置错误输入
2 cin.sync();//清空缓冲区  


 

posted @ 2013-02-07 22:59  阿津  阅读(241)  评论(0编辑  收藏  举报