ChinaUnix.net
相关文章推荐:

cin 返回值

//兄弟姐妹们,看这段代码,为什么当我非法输入,比如输入字符时,它就不能正常 //工作了呢?按道理它如果检测到输入非法,cin就应该复位了呀?而且我既setstate, //又clear,双管齐下,这头不着那头着,也应该有一个管用呀?彻底死鸡了,等待中... #include; #include; using namespace std; void main() { int sa; int times=3; while(times--) { cin>;>;sa; if(!cin.good()) { cout<<"bad 2"<

by isnowran - C/C++ - 2003-10-10 13:12:52 阅读(1011) 回复(2)

相关讨论

新手.. 有这样一个题目:编写一个程序, 一次显示文件的一行, 然后, 等待用户按回车键后显示下一行。 我这样写: #include #include #include using namespace std; int main() {   string line;   ifstream in("enter.cpp");   while (getline(in, line)) {     cout << line;     string input;    &nb...

by netrookie - C/C++ - 2009-07-18 15:05:12 阅读(1396) 回复(6)

cincin.get()有什么不同? cin.get()是不是与EOF配套使用,而cin不可以呢???

by nianshan - C/C++ - 2008-04-17 13:26:03 阅读(1172) 回复(0)

[code] #include #include using namespace std; int main() { int ch; do { system("clear"); cout<<"请选择文件类型:"; cin>>ch; if(1==ch) { cout<

by xiechunlu - C/C++ - 2006-11-15 15:30:37 阅读(1185) 回复(2)

我写了段代码,是一个“数学魔术”。 代码如下: [code] #include using namespace std; int main() { int number = 0; // 用户所想的数字 int n; // 卡片号 cout << "请在心中默想一个0-31的数字。然后在下面的5张卡片中查找你所想的数字:\n" "卡片1: 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31\n" "卡片2: 2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31\n" "卡片3: ...

by lixuzhang - C/C++ - 2006-04-05 16:37:40 阅读(3671) 回复(2)

#include; #include; void main() { char str[20]; while(getchar()!='#') { cin.getline(str, 20); } cout <cin.getline()函数,但是不知道怎么结束循环?上面那样做不能使循环结束。

by xiaozhang353 - C/C++ - 2004-12-31 17:20:12 阅读(2815) 回复(2)

#include ; void main() { char str[128]; cout<<"type in a line of text and press enter"<cin.getline (str,sizeof(str),'x'); cout <<"first line:"<cin.getline (str,sizeof(str)); cout <<"second line:"<

by ylx_2002 - C/C++ - 2004-03-26 23:39:00 阅读(1409) 回复(1)

#include ; #include ; using namespace std; int main(int argc, char** argv) { string temp; cin >;>; temp; return 0; } 如果输入某字符串后按回车,则正常退出 如果直接按回车,则永远不能退出,请问能否让程序退出? 谢谢

by bjchenxu - C/C++ - 2004-01-08 14:40:48 阅读(674) 回复(2)

源代码是: #include using namespace std; int main(){ double radius; cout<<"Please input radius:" cin>>radius; double result = radius*radius*3.14*4; cout<<"The result is "<cin>>radius;时,应该有个...

by jiushigeceshi - C/C++ - 2009-02-02 20:39:39 阅读(1812) 回复(8)

int i; cin >> i; while (cin.fail()) { cout << "Input error, try again: "; cin >> i; } 如上语句,但在执行时,当输入非int值(比如字符)会陷入死循环,我不太明白cin.fail()的作用,书上说是可以检测类型不匹配和EOF

by ragnarok430 - C/C++ - 2008-11-24 01:03:56 阅读(1278) 回复(1)

cin.get() #include using namespace std; int main( ) {char ch[20]; cin.get(ch,20,'/'); cout<<"The first part is:"<cin.ignore( );//跳过输入流中一个字符 cin.get(ch,20,'/'); cout<<"The second part is:"< using namespace ...

by liuguilg - C/C++ - 2008-04-27 17:27:15 阅读(1737) 回复(0)