View Single Post
Old Dec 10th, 2005, 5:40 PM   #1
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
trouble reading string into array

so i've got this string called code, of type std::string, which has this inside it

Quote:
1
2
3
4
and yes i've verified this by using cout. now im trying to read each line into a seperate element of the array statements, which is also of type std::string. when i run the below code however:

int last_flushed = 0;
std::string statements[1000];
int array_pos = 0;
for (int i = 0; i <= code.size(); i++)
{
	if (code[i] == '\n')
	{
		statements[array_pos] = string_copy(code, last_flushed, i - last_flushed);
		cout << statements[array_pos];
		array_pos++;
		last_flushed = i;
	}
}

it just prints out this:

Quote:
1

2
any idea why this is happening? ive been staring at this for a day or so, i feel really stupid right now. thanks in advance for your help.
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote