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 |
Re:一点接受输入经验, gets(char *)、getline(basic_istream is, string& str)In Reply To:一点接受输入经验, gets(char *)、getline(basic_istream is, string& str) Posted by:userfriendly at 2008-07-23 01:18:24 > 首先输入的是case的总数,int n; cin>>n 或者 scanf("%d", &n) 读入后 > 这时输入流中还有一个'\n'字符!, 必须读掉这个字符, 可以用 char c[xx]; gets(c); 或者string str, getline(cin, str); > 之后就可以正常按行读取两个字符串, 否则getline将读到之前残留的'\n'从而得到一个空行! > > 应注意到cin, scanf并不读掉流中的换行符。 > ^_^ 实际上 scanf("%d ",&n)即可. 注意与scanf("%d", &n)的区别. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator