Writing to a string array

Hello!

Could anyone help me with writing characters to a string array

I'm trying to read text file which contains several commands. I want to store each command I detect in array, where each slot will contain 1 command.

Firstly, program detects how many commands is there in the file, number is stored in variable i, then creates appropriate string array and tries to write character-by-character commands to a array using while loop.
it2 is character readen from a text file, which has to be written into a array

problem of the code below is that it does not writes anything to a command array... what am i doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
	
<...>
int inc=0;
string *command;
command=new string[i];
while( ! infile.eof() )
{<...>
if (NoNewCommand == true) 
command[inc]=command[inc]+it2;
else inc++; <...>
}

<...>


PS im using <...> just to note there is more code, which is working correctly.
Last edited on
Change your while loop to this:

1
2
3

while( ! infile.eof() )

yeah sorry about that, i was retyping this loop and missed ! sign, it is in the actual code
Last edited on
Well, if you are still not entering your while loop, you might look at the infile flags to see if the constructor failed:

1
2
3
4
5
6
7

if( infile.bad() )
    cerr << "infile is bad!" << endl;

if( infile.fail() )
    cerr << "infile failed!" << endl;
Topic archived. No new replies allowed.