Hi what is the solution ?
i have a file like this :
0 1 2 C
10 1 2 S
7 1 2 C
11 1 2 S
9 3 43 C
10 3 43 S
1 3 43 C
101 3 43 S
with this code :
ifstream in("fout2.txt");
if (in) {
vector<string> lines;
string line;
while (getline(in, line))
lines.push_back(line);
sort(lines.begin(), lines.end(), [](const string& a, const string& b) {
// Use the first word for comparison
return a.substr(0, a.find_first_of(' ')) <
b.substr(0, b.find_first_of(' '));
});
for_each(lines.begin(), lines.end(), [](const string& s) {
std::cout << s << '\n';
});
}
i obtaint this :
0 1 2 C
1 3 43 C
10 1 2 S
10 3 43 S
11 1 2 S
101 3 43 S
7 1 2 C
9 3 43 C
but i want an output like this :
0 1 2 C
1 3 43 C
7 1 2 C
9 3 43 C
10 1 2 S
10 3 43 S
11 1 2 S
101 3 43 S
thanks