Reading from txt file as 2D vector

Hi everyone,

I'm confused if whether or not the following is possible...

I have a .txt file that has something like the following:

123; John Smith; 1000
14; David Adams; 3203
1425; Kobe Lee; 90233

Is there a way I can read from this txt file as a 3x3 vector?

I'm ultimately trying to create a code that would read the first column [i][0] and check to see if user input is a duplicate to any of the numbers in the first column.

Sorry for not posting a code; I'm struggling to even conceptualize this code - would I use loops? Initialize 2D vector before opening a stream?

Thank you so much!

Create a vector of structures:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct foo
{
    int id;
    std::string name;
    int some_number;
};
//...
std::vector<foo> data; //A vector of structures
//...
foo temp; //temporary structure
file >> temp.id; //read id
file.get();  //skip ;
std::getline(file >> std::ws, temp.name, ';'); //read name
file >> temp.some_number; //read number
data.push_back(temp); //place complete structure in vector 
Topic archived. No new replies allowed.