getchar();
getline(cin, str);
使用前读完行尾回车
7-5 使用函数实现字符串复制 (10 分)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int main()
{
int T, p;
cin >> T;
getchar();
while (T--) {
string str;
getline(cin, str);
cin >> p;
getchar();
if (p > str.size()) cout << "error input" << endl;
else cout << str.substr(p-1) << endl;
}
return 0;
}