Any idea how to read this?

Any idea how to read this?
6
Raudona, 2 2 4 2 8 3 6 3 9 8 1 2
Mėlyna, 3 -4 9 -4 6 -10
Šviesiai violetinė, 9 4 -1 -3 5 6 9 7
Geltona, 9 8 5 3 4 1 8 3
Oranžinė, 2 9 5 7 9 6 3 9
Tamsiai žalia, 1 9 2 5

How to read txt file if numbers int he line are not the same.?.
That depends on if you're using C or C++. In C++ it's actually rather trivial.

EDIT:
1
2
std::getline(istream_instance, string_buffer, char_delimiter);
//Reads until char_delimiter is found. By default, the delimiter is '\n'. 


-Albatross
Last edited on
I'm using c++. But I don't get it. Is there any example of how to use this thing? :/. And words i need to read to string and numbers to int'eger. so is it possible? thanks.
Last edited on
Here's one way. Read the whole line and then use a stringstream in order to get the values from that line. identify the end of the name by using getline with a comma as the delimiter.
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    ifstream fin("input.txt");
    string line;
    
    while (getline(fin, line))     // read whole line 
    {
        istringstream ss(line);    // construct stringstram from line
        string name;
        getline(ss, name, ',');    // use comma delimiter to get name
        cout << "Name: " << setw(20) << left << name;
        cout << " Numbers: ";
        int n;
        while (ss >> n)            // read all the numbers
            cout << n << " ";
        cout << endl;    
    }
}

Output:
Name: Raudona              Numbers: 2 2 4 2 8 3 6 3 9 8 1 2
Name: Me.lyna              Numbers: 3 -4 9 -4 6 -10
Name: èviesiai violetine.  Numbers: 9 4 -1 -3 5 6 9 7
Name: Geltona              Numbers: 9 8 5 3 4 1 8 3
Name: Oran×ine.            Numbers: 2 9 5 7 9 6 3 9
Name: Tamsiai ×alia        Numbers: 1 9 2 5
Topic archived. No new replies allowed.