C++ 打开一个文件;但是跳过每一行
我想知道如何在使用C++ 打开一个文件;但是跳过每一行,c++,fstream,C++,Fstream,我想知道如何在使用fstream打开文件时跳过行。当我打开文件时,它返回所有聚集在一起的数字,如“201051535402530” 这是我的密码 #include <iostream> #include <vector> #include <fstream> #include <string> using namespace std; int main() { string testing; ifstream myfile;
fstream
打开文件时跳过行。当我打开文件时,它返回所有聚集在一起的数字,如“201051535402530”
这是我的密码
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string testing;
ifstream myfile;
myfile.open ("inputfile");
while (!myfile.eof())
{
getline(myfile, testing);
cout << testing;
}
return 0;
}
当getline()
读取一行时,它会丢弃尾随的换行符。如果您想在输出中打印一个,您需要自己将其放在那里:
cout << testing << endl;
cout Changecout或cout,谁在(!eof)
时教?这是错误的。
cout << testing << endl;