Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一点接受输入经验, gets(char *)、getline(basic_istream is, string& str)

Posted by userfriendly at 2008-07-23 01:18:24 on Problem 2681
首先输入的是case的总数,int n; cin>>n 或者 scanf("%d", &n) 读入后
这时输入流中还有一个'\n'字符!, 必须读掉这个字符, 可以用 char c[xx]; gets(c); 或者string str, getline(cin, str);
之后就可以正常按行读取两个字符串, 否则getline将读到之前残留的'\n'从而得到一个空行!

应注意到cin, scanf并不读掉流中的换行符。
^_^

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator