【发布时间】:2020-04-08 19:45:49
【问题描述】:
例如,我有一个文本文件名为 example.txt。它有两列。
12561 60295
13561 60297
13561 60298
13461 60299
15561 60300
15161 60301
15561 60302
14561 60316
12561 60317
10562 60345
15562 60346
15562 60347
15562 60348
15562 60362
19562 60363
11562 60364
12562 60365
15563 60408
15563 60409
75563 60410
65563 60411
14563 60412
13563 60413
我可以读取宏后面的文本文件:
#include <bits/stdc++.h>
using namespace std;
// driver code
int main()
{
vector<int> column1;
vector<int> column2;
fstream file;
string word, filename;
filename = "example.txt";
file.open(filename.c_str());
while (file >> word)
{
// displaying content
cout << word << endl;
}
return 0;
}
我要做的是将第一列推回向量column1,将第二列推回向量column2。
因此向量 1 和 2 的输出将是:
vector<int> column1 {12561,13561,13561,...}
vector<int> column2 {60295,60297,60298,...}
【问题讨论】: