Getting an array from a txt file

Thread Solved

Join Date: Jun 2005
Posts: 4
Reputation: Greenthumb is an unknown quantity at this point 
Solved Threads: 0
Greenthumb Greenthumb is offline Offline
Newbie Poster

Getting an array from a txt file

 
0
  #1
Jun 7th, 2005
Hi everyone, i was hoping i could find some help here.
I am trying to get settings i have written into a textfile to be put in an array.
Here is what is in the txt file:

8
44100
1
2
1

I read the textfile with:

pStream = new FileStream(strSavePath, FileMode::Open);
pReader = new StreamReader(pStream);
count = 0;
for(;;)
{
count++
strLine = pReader->ReadLine();
Console::WriteLine(strLine);
if(strLine == 0)
break;
}

Now i want the strings i read from the txt file to be put into an array, with each new line being a new index of the array.
Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 48
Reputation: amt_muk is an unknown quantity at this point 
Solved Threads: 3
amt_muk amt_muk is offline Offline
Light Poster

Re: Getting an array from a txt file

 
0
  #2
Jun 7th, 2005
Hi Greenthumb,

You can try this:

  1. pStream = new FileStream(strSavePath, FileMode::Open);
  2. pReader = new StreamReader(pStream);
  3. count = 0;
  4. int array[100];
  5. for(;;)
  6. {
  7. strLine = pReader->ReadLine();
  8. Console::WriteLine(strLine);
  9. if(strLine == 0)
  10. break;
  11. array[++count] = atoi(strLine);
  12. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: Greenthumb is an unknown quantity at this point 
Solved Threads: 0
Greenthumb Greenthumb is offline Offline
Newbie Poster

Re: Getting an array from a txt file

 
0
  #3
Jun 7th, 2005
Thanks, i got it to work now .
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC