Archived

This topic is now archived and is closed to further replies.

Betrayer_of_Code

Getline fuction

Recommended Posts

Can getline() be used for loading numbers in a txt file into an array? for(int r = 0; r < 10; ++r) { for(int c = 0; c < 10; ++c) { getline(fin, maze[c][r]); } } That doesnt seem to work. I am just finished writing a maze solver, and Im trying to figure out a way to get mazes loaded from a txt file rather than from the .cpp file, taht way anyone can edit it. If getline() cant be use, what can? Thanks for the help,

Share this post


Link to post
Share on other sites
Why not just input each integer into an integer array...?

inside loops
fin >> maze[c][r];
(though that would require spaces)

alternatively you could

char dummy;

(inside loops)
fin >> dummy;
maze[c][r]=convertToInt(dummy);

(and you'd obviously have to define convertToInt())

[edited by - woodsman on January 23, 2004 6:18:33 PM]

Share this post


Link to post
Share on other sites
Not unless you have an array of strings (read the freaking function prototype). Use ordinary stream extraction instead.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
stream << variable; // Stream insertion
stream >> variable; // Stream extraction


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites