[英]Issue with getline from file
我正在尝试从.txt文件中读取行,并使用std::cout
它们打印出来。 我的代码发布在下面,但是在while循环期间当前没有向向量传递任何行。 我哪里做错了?
int main(int argc, const char * argv[]) {
std::ifstream input("input1.txt");//(argv[1]);
if (!input.good()) {
cerr << "Can not open the grades file "; //<< argv[1] << "\n";
return 1;
}
std::vector<string> art;
string x; // Input variable
// Read the scores, appending each to the end of the vector
cout << "Start While:"; //For Debugging Purposes
while (getline(input, x)) {
art.push_back(x);
}
for (int i=0; i<art.size(); i++) {
cout << art[i] << "\n";
}
return 0;
}
事实证明Xcode很难。 在移动了几个文件并在编译器中运行后,它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.