Hi I currently have a list of text files that are in order, text01, text02, text03 etc etc.. the list is always different day to day but they are rewritten in the same directory, so somedays there are 5-10 text files and another day up to 300 text files or more (point being I am unsure of the limit)
I open the text file, grab the first 4 lines from it and store that in a string array named Line[]. with the following code:
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
|
//Main Function
int main ()
{
//Opening Text file for reading
ifstream textFile;
textFile.open ("text01.txt") ;
//Close Program if unable to open Text File
if (! textFile.is_open () )
{
cout << "Unable to open file" << endl;
return 0;
}
//Array for the lines of text
string Line[4];
//Loop each line of text and then store it in the Line array
for (int i = 0; i < 4; i++)
{
getline (textFile, Line[i]);
}
//Close File now we are done with it
textFile.close();
}
| |
I am fairly new to c++ so this is the best solution I could come up with to grab the 4 lines and store them (is this the most efficient way?)
But efficiency aside I want to be able to open the next sequential text file which will be text02 (without writing the file names individually I want c++ to follow the naming convention)
Once I figure out how to do that (your help please!) would I then turn Line[4] into a 2d array? Line[4][?] (? is because i dont know how many files It would be) so my assumption would be that it works something like this:
Line[4]contains 4 lines collected from the text file, and the second bracket of the 2d array would contain which text file is stored so if I wanted the second line of text from text01 I would use:
Line[1][0];
If I wanted the second line of text from text02 I would use:
Line[1][1];
This may be completely incorrect I am kind of just trying to make an educated guess and I have not got to the vectors chapter yet so any insight would be really appreciated!
Cheers,
Ben.