当前仅尝试编辑一些基本输入以摆脱单数“。”。在一行的开头。 但是,这仅在我强制EOF时起作用。我在uni网站上对此作业的提交评论似乎陷入了while循环中,并且没有输出结果。输入量最多可以达到1000行,我似乎想不出如何最好地接收输入而不被卡住。 main.cpp如下:
示例输入和输出为:
Input:
..hello
.hello
hello
Output:
.hello
hello
hello
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int main(int argc,char *argv[])
{
string inputLine;
vector<string> vect;
string s;
string temp;
while (getline(cin,s)) {
vect.push_back(s);
}
for (int i = 0; i < (int)vect.size(); i++) {
temp = vect[i];
if (temp[0] == '.') {
for (int k = 0; k < (int)temp.length(); k++) {
temp[k] = temp[k + 1];
}
}
vect[i] = temp;
}
for (int j = 0; j < (int)vect.size(); j++) {
cout << vect[j] << endl;
}
return 0;
}