Hi everyone. I new to c++ programming. I would like to ask regarding reading an array from text file. Given an input data as follows:
Input data (in .txt):
0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 4 8 9 5 11 10 2 12 7 3 6 1 0
0 5 8 9 4 11 10 2 12 7 3 6 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 9 8 5 4 11 10 2 12 7 3 6 1 0
0 10 11 9 8 5 4 1 7 3 6 12 1 0
0 11 10 9 8 5 4 1 7 3 6 12 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
Each line represents each solution. For example line 1 illustrates the initial route 1, line 2 is the initial route 2 and so on. I had done with coded in which store the particular data into array (read line by line).
The question is, what if later on i want to solve the following question.
initialroute[0][3]= 5
initialroute [9][3] = 9
Hopefully you understand what i meant. Hoping anyone could help me.
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 27 28 29 30 31 32
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int route = 0;
string line;
stringstream lineStream;
ifstream inpInitialRoute("Route.txt");
//read lines
while( getline(inpInitialRoute, line) )
{
lineStream.clear();
lineStream.str(line);
cout << "Initial route" << route++
<< "= " << lineStream.str() << std::endl;
}
inpInitialRoute.close();
system("pause");
return 0;
}
|