#include<iostream>
int main()
{
using namespace std;
char ch;
int count=0;
cout<<"Enter characters;enter # to quit;"<<endl;
cin>>ch;
// cin.get();
while(ch!='#')
{
cout<<ch;
++count;
cin>>ch;
// cin.get();
}
cout<<endl<<count<<" characters read"<<endl;
// cin.get();
// cin.get();
return 0;
int main()
{
using namespace std;
char ch;
int count=0;
cout<<"Enter characters;enter # to quit;"<<endl;
cin>>ch;
// cin.get();
while(ch!='#')
{
cout<<ch;
++count;
cin>>ch;
// cin.get();
}
cout<<endl<<count<<" characters read"<<endl;
// cin.get();
// cin.get();
return 0;
}
在while循环中的cin输入语句起到什么作用,另外,在VS2010中,这个程序无法捕捉画面,运行结果一闪即逝,我加了cin.get()也没用,还请大神帮帮忙
1:cin是C++中字符读取的函数,在未遇到最后一个字符的时候,cin返回的都是true,如果遇到了结束,则返回的是false
2:字符串指针数组:
const char * cities[5]={"asd","sds","sds","www","fff"};
char数组
char maxtemps[2]={"sdsd","ddddd"};
string对象数组
const string cities[3]={"sada","dfdsf","gfgr"};