|
-
February 19th, 2008, 09:17 PM
#1
File I/O help
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
Code:
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?
-
February 19th, 2008, 09:56 PM
#2
Re: File I/O help
sorry, i got it to work. i didnt know that getline automatically marks the lines it has already read.
disregard this post
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|