如何将txt文件里的东西存放到字符串组里?
我用的是Linux C++。 用vim编辑器。如何将txt文件里的东西存放到字符串组里面?
一个字符串应包含一个行的内容。
谢谢!
2018-11-12 01:47
程序代码:#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main( void )
{
vector<string> ss;
{
ifstream file( "a.txt" );
for( string s; getline(file,s); )
ss.push_back( s ); // 若嫌效率不高,那 move(s)
}
return 0;
}
2018-11-12 09:05
2018-11-12 16:20