-1
如果您在回答中编写代码,请将其写入,就好像您使用的是namespace std ;.否则,它是我很难阅读:)如何从文本文件的每一行输入N个字符到字符串?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int a; // a is amount of lines in file
string word[100];
int main()
{
ifstream fd("file.txt");
fd >> a;
for(int i=0; i<a; i++)
{
//here goes the code which inputs, let's say, 20 first characters of a line into string array - word[i].
}
fd.close();
return 0;
}
什么'的fd <<了'为?? – Raindrop7
FD >> A;将显示文本文件中有多少行,这样我就知道我的for循环需要循环多少次 –
,所以你存储了t他想要读取的文件内的行数? – Raindrop7