File Pattern

Hey guys,
i need some help with file pattern. I'm in a project that i read a file and the program makes a matrix.
the file pattern is
1;4;4
2;6;6
3;2;2
4;20;20;

where the first number before ';' is the code of the matrix, the second one is the row and the last one is the column.

i have no idea how i can put the code, row and column in an int variables
this is my function so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void Matrix::getLine()
{
	string line;
	stringstream cod, row, col;
        int i_cod, i_row, i_col;

	while(File->getFile().good())
	{
		getline(File->getFile(), line);
		{
			for(string::iterator it = line.begin();
				it != line.end();
				++it);
				/*i'm thinking to use some algorithm here
				to put the firt number before ';' in the cod
				stream, the number between the ';' in the row
				stream, and the last number after the ';' in the
				col stream.And after that convert the streams to 
				an int variables*/
		}
	}
}


what i can do here??
I don't have to use iterator, i just thought to solve that splitting the file in characters.
Is there an easier way to do this?
I appreciate any help.
Thank you very much
Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
std::ifstream file( "matrix.txt " ) ;
std::string line ;
while( std::getline( file, line ) )
{
    std::istringstream stm(line) ;
    int data ;
    unsigned int row, col ;
    char sep1, sep2 ;
    constexpr char COLON = ';' ;
    if( ( stm >> data >> sep1 >> row >> sep2 >> col ) )
    {
        if( ( sep1 == COLON ) && ( sep2 == COLON ) &&
            ( row < num_rows ) && ( col < num_cols ) ) matrix[row][col] = data ;
        else { /* handle error in input */ }
    }
}
Topic archived. No new replies allowed.