0

My text file looks like this :

my bag;A5;B5;C5;D5;E5
watch;E4;F4;G4;H4
the sofa;F6;G6;H6
handphones;C2;D2;E2
babies;D6;D7

i am trying to save each line into an array like this:

string type[100];
string line;
int count = 0;
string item1;

ifstream infile;
infile.open("txtmess.txt");

while (getline(infile, line))          

            {     
           //cout<<line<<endl; //just to check
            type[count] = fline;       
            count++;                  
            stringstream ss(type[count]);                   
            getline(ss, item1, ';'); 
            cout<<type[count]<<endl; //not printing . 
            cout<<item1<<endl;       //not printing .           

            }
infile.close();

I am trying to save each line of the text file into an array like this

type[0] =   my bag;A5;B5;C5;D5;E5
  type[1] =   watch;E4;F4;G4;H4
 type[2] =    the sofa;F6;G6;H6
 type[3] =    handphones;C2;D2;E2
  type[4] =   babies;D6;D7

However when i try to cout the array it prints a blank

What i want to do is to split each array ( type[] ) by another getline like this and save into another array :

// extracted from above code in the while loop //
stringstream ss(type[count]);                   
getline(ss, item1, ';'); 
cout<<item1<<endl;
//another whileloop inside a whileloop to save item1  into an another array?
what
  • 373
  • 2
  • 10
  • 20
  • [mcve] please. I'm pretty sure that if I try to rebuild your test case I'll get it wrong and be unable to duplicate your bug. – user4581301 Nov 14 '16 at 05:23
  • Are you sure the printing of the string isn't the problem itself? Take a look at [here](http://stackoverflow.com/questions/6320995/why-i-cannot-cout-a-string) – Steeve Nov 14 '16 at 08:56

0 Answers0