Dwellerofholes
February 19th, 2008, 08:17 PM
um, this is what im tring to do
i have a text file made of 0 and 1 like in the configuration of a maze. What i want to do is read the file and place the data into a 2d matrix. I tried to use getline but i couldnt figure out the right syntax. Now, what im going to do is a loop where i get an entire line and store it onto a string. then copy that string into the first portion of the 2d matrix. then im going to iterate it. kinda like this
string str; //string copied from getline
int array[10][10]; //array eventually copied into
int linecounter=0; //loops until every line is copied
while (linecounter<10){
//somehow copying a line of the text, a new line each time and putting it into the string str
for (int i=0;i<11;i++){ //this iterates storing the strings
array[i][]=str
}
}
Is there an easy way that im overlooking?
or am i on the right track?
and also, how can i use getline to get the first line, then the next time get the second line, and so on?
i have a text file made of 0 and 1 like in the configuration of a maze. What i want to do is read the file and place the data into a 2d matrix. I tried to use getline but i couldnt figure out the right syntax. Now, what im going to do is a loop where i get an entire line and store it onto a string. then copy that string into the first portion of the 2d matrix. then im going to iterate it. kinda like this
string str; //string copied from getline
int array[10][10]; //array eventually copied into
int linecounter=0; //loops until every line is copied
while (linecounter<10){
//somehow copying a line of the text, a new line each time and putting it into the string str
for (int i=0;i<11;i++){ //this iterates storing the strings
array[i][]=str
}
}
Is there an easy way that im overlooking?
or am i on the right track?
and also, how can i use getline to get the first line, then the next time get the second line, and so on?