954,167 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

input data from a file into an Array

help!
im trying to input data from a file into an array. I cant figure it out...this is what i have:


inData.open(fileName.c_str());

int i=0;
while(inData)
{
inData >> T[i];
i++;
size++;
}

thanks

Foxtildawn
Newbie Poster
15 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

What you have should work, unless I'm too tired to see a problem. Another way to write it would be

inData.open(fileName.c_str()); 

for (int i = 0; inData>> T[i]; i++)
  ++size;
Siersan
Light Poster
45 posts since Jan 2005
Reputation Points: 12
Solved Threads: 2
 

have you got any more code as if there is a problem you might need to show us the whole program. there is a good fstream tutorial on the site that can solve problems... :) Im not entirely sure but my RLE compression / De-compression snippet MIGHT have file -> array code, but I think I performed the routine "on-the-fly"....

1o0oBhP
Posting Pro in Training
445 posts since Dec 2004
Reputation Points: 16
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You