C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| #include <vector>
#include <iostream>
#include <fstream>
#include <functional>
#include <sstream>
#include <string>
int main()
{
std::ifstream fin("in.txt");
using T_data = std::pair<int, int>;
using T_row = std::vector<T_data>;
using T_vec = std::vector<T_row>;
T_vec v;
std::string str;
while(std::getline(fin, str))
{
std::istringstream iss(str);
T_row r;
while(!iss.eof())
{
T_data d;
iss >> d.first;
if(!iss.eof())
iss >> d.second;
r.emplace_back(d);
}
v.emplace_back(r);
}
for(const auto& row: v)
{
for(const auto& data: row)
std::cout << "(" << data.first << ", " << data.second << ") ";
std::cout << std::endl;
}
fin.close();
return 0;
} |
|
По хорошему надо бы еще проверять на наличие посторонних символов в файле. Но это уж сами.