Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a optimization problem to solve using cplex concert technology in c++ I have data in csv file format the data look like:

PR;tie0(0);tie0(1);tie0(2);tie0(3);tie1(0);tie1(1);tie1(2);tie1(3)
1,4;5;10000000;10000000;4;10000000;10000000;10000000;10000000
2,6;10;7;8;10000000;7;10000000;10000000;10000000
3,9;10000000;10000000;10000000;10000000;13;10000000;10000000;10000000
4,5;5;10000000;10000000;10000000;3;10000000;10000000;10000000
5,6;6;10000000;10000000;10000000;10000000;10000000;10000000;10000000
6,7;8;6;10000000;6;10000000;10000000;10000000;10000000
7,8;7;10000000;10000000;10000000;10000000;10000000;10000000;10000000
7,9;4;10000000;10000000;3;10000000;10000000;10000000;10000000
9,10;10000000;10000000;10000000;10000000;5;10000000;10000000;10000000
;13;10000000;10000000;10000000;10000000;10000000;10000000;10000000

I have to use PR(precedence relation of tasks) and tie(Time data on conditions
Below is my code to read this file.My code is able to read display content of this file perfecly but I want to use this in my code how to do it or store it arrays like PR[][], t0[][],t1[][]

C++
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<string>
#include<stdio.h>

using namespace std;
int main()
{
     string filename;
     int PR[10][2];
     cout << "\nDrag input file here: ";
     getline(cin , filename);
     ifstream instream;
     instream.open(filename.c_str());
     if (instream.fail())
     {
            cout<< "Input file opening failed.\n";
     }
     getline( instream,filename, '\n' );
     instream >> PR[0][0];
     getch();
     return 0;
}
Posted
Updated 23-May-13 14:55pm
v2
Comments
[no name] 23-May-13 12:47pm    
I am not sure what it is that you are asking. Seems to me that you are simply asking how to use a multidimensional array... http://www.learncpp.com/cpp-tutorial/65-multidimensional-arrays/
mohit_mnc 23-May-13 12:59pm    
how to put these data into array so that I could use them in my program
[no name] 23-May-13 13:06pm    
You would need to tokenize the data and then put the data into your array.
mohit_mnc 23-May-13 13:09pm    
I want to store the data into three arrays PR[][], t0[][], t1[][] for PR, tie0, tie1 could you put some light how to do it
[no name] 23-May-13 13:13pm    
Tokenize the data and then put the data into your arrays

1 solution

you need to work with loops, indexes and some parsing like

int i = 0;
char buff[200];

while ( getline( instream,filename, '\n' ) )
{
//process the line
instream >> buff;
PR[i][0] = atoi(buff);
char *p = strTok(buff,',');
PR[i][1] = atoi(p);

p = strTok(p,',');
PR[i][2] = atoi(p);
/... and so on

//next
i++;
}

Read some basic stuff about working with arrays
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900