Hey, could someone help me out by telling me how I can read in 2 matrices from a single input file?

What have you tried so far? It will be helpful to know the layout of the input file also.

I'm new to posting online, but I guess I should have given more info :)
Here is the code I managed to write and the input file.

I'm new to posting online, but I guess I should have given more info :)
Here is the code I managed to write and the input file.

try something like this, i fill a vector of vectors with the values find in the file.. is not finished but i could help

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <string>
#include <sstream>

using namespace std;

#define ROW vector<int>

int main ()
{
	ifstream fin("Input.txt", ifstream::in);
	ofstream fout("Output.txt");

	if(!fin.is_open())
	{
		cerr << "Unable to open file";
		exit(2);
	}

    int number;

	vector<ROW> matrix;
	while(!fin.eof())
	{
        string fila;
        getline(fin, fila);
        vector<int> row;

        // convert to number
        istringstream str(fila);
        while(!str.eof())
        {
            str >> number;

            // ok?
            if (str)
            {
                cout << " " << number;
                row.push_back(number);
            }
        }

        // end of row
        cout << endl;
        matrix.push_back(row);
	}


	fin.close();
	fout.close();
	return 0;
}

Thank you for the help, sorry I didn't write back earlier, but I after a few changes (major in some places) I ended up with 5 functions and everything worked out nicely :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.