Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ reading textfile into 2d array

Name: Anonymous 2009-12-01 14:20

Ok, anon. I am trying to teach myself C++ and one thing I would like to be able to do is read a text file that is 4 x 4 characters
xxxx
xoxx
xxox
xxxx

into a 2d char array of [4][4]

but I'm pretty confused and google seems pretty shit searching for more specific stuff like this

I can open/close files and print arrays to the screen and shit I just don't know how to assign the characters in the text file to the array.

thanks ;]

Name: Anonymous 2009-12-01 14:25

I am trying to teach myself C++
Now is a good time to stop.

Name: Anonymous 2009-12-01 14:41

>>1
Ok, anon.
back to /b/, please

Name: Anonymous 2009-12-01 14:44

Just ask this on StackOverflow.

Name: Anonymous 2009-12-01 15:05

I recommend implementing a class called FileArrayReader that inherits from ifstream.

Name: Anonymous 2009-12-01 15:44

>>1
You don't know how to do WHAT?

Use two loop indices to indicate array indices - array[j][i], where 0 <= i,j < 4.  Read the file one character at a time and put that character into the array at the given column position; then, increment the row index, set the array column index back to 0, and start reading the next line; keep going until eof or array full.

Name: Anonymous 2009-12-01 16:10

>>6
Hey, YOU HELPED HIM! Why did you do that? Why would anyone do that?

Name: Anonymous 2009-12-01 16:11

>>2
OP, this is not a joke. C++ is the joke. Stop now.

Name: Anonymous 2009-12-01 16:37

>>7
No, the one who helped OP before that was >>4-kun.

Name: Anonymous 2009-12-01 17:30

>>1
The simpler thing to do (usually) is to read a text file of 16 characters into an  array of 16 characters.

Then make a marco that transforms 2D coordinates into 1D coordinates.

Name: Anonymous 2009-12-01 18:24

>>10
polo

Name: sage 2009-12-02 8:15

wholesale naked coeds

Name: Anonymous 2011-02-03 0:13

Name: Anonymous 2013-06-18 18:28

Name: Anonymous 2013-06-18 18:35

Name: Anonymous 2013-06-18 18:42

Name: Anonymous 2013-06-18 18:49

Name: Anonymous 2013-06-18 18:55

Name: Anonymous 2013-06-18 19:02

Name: Anonymous 2013-06-18 19:09

Name: Anonymous 2013-08-27 13:51

check 'em

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List