Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
cin>>s之后用cin.ignore()吃掉换行In Reply To:谁能告诉我这是为什么 讨厌的getline Posted by:xiaxia at 2006-04-09 16:31:09 > 总觉得getline有问题 > 如果输入 > > START > NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX > END > > > > while(cin >> s && s != "ENDOFINPUT") > // 这一步 s = START 没错 > //下一个循环这里的S = “BFW,"吃掉第二个。 > { > getline(cin, input); > //第一次可是getline后 input竟然是空的 设么都没有 > //第二次此时input = "JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX" 已经不完整了 > int i, k; > for(i = 0; i < input.length(); i ++) > { > if(input[i] >= 'A' && input[i] <= 'Z') > { > k = input[i] - 'A'; > k = ((k - 5) + 26)%26; > input[i] = 'A' + k; > } > } > //上面循环自然不进行了 > cout << input << endl; > //输出个空循环 > cin >> s; > //这是的s = "NS"把一行的吃掉前一个单词 > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator