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

C++ / read data from file into 2d array

Name: Anonymous 2011-09-26 18:08

This problem is giving me a headache. I need to read in a file into a 2D vector that looks like this.

data data # data data # data data # #
data data # data data # data data # #
#

I am using a function that only reads until a # is encountered, then it is supposed to store whatever came before it in the vector, and return a boolean true (because the first string read in was not a # sign). If a # is read in as the first string, it returns false, the end of the line, at which point I would advance one row and then continue reading in the next row. Two false returns in a row signals the end of file.

I have that part working correctly. What is not working is actually storing the string into the 2D array.

s.clear(); // s is passed by reference and cleared each time
string temp;
infile >> temp;
while (temp.compare("#"))
{
  s.append(temp); // append temp to s
  temp.clear();   // clear temp to be read in again
  infile >> temp;
}

Right, ok, so s holds the data I want to store into my 2D array. Simply using it like 2d_vector[0][0] = s; obviously doesn't work.

2d_vector.push_back(s); doesn't work either.

Any insight would be appreciated.

Name: Anonymous 2011-09-26 18:11

Subject: C++

This problem is giving me a headache.

I can fix that.  Drop the ++.

Name: Anonymous 2011-09-26 18:36

Any other advice?

Name: Anonymous 2011-09-26 19:00

1: error: ‘s’ was not declared in this scope
2: error: ‘string’ was not declared in this scope
2: error: expected `;' before ‘temp’
3: error: ‘infile’ was not declared in this scope
3: error: ‘temp’ was not declared in this scope

Name: Anonymous 2011-09-26 19:30

THAT WAS BANGALORE QUALITY

Name: Anonymous 2011-09-26 20:43

The jews are after me.

Name: Anonymous 2011-09-26 20:54

Use regexes, ``faggot''.

Name: Anonymous 2011-09-26 22:35

>>1
Use [m][code][/m] tags.

Name: Anonymous 2011-09-26 22:36

* [code]

Name: Anonymous 2011-09-26 23:55

Don't program in C++.

Name: Anonymous 2011-09-27 6:03

SLACKWARESUPREMACYSLACKWARESUPREMACY

Name: Anonymous 2011-09-27 7:30

>>11
Failed attempt at granting ``SLACKWARESUPREMACY'' meme status.

Name: Anonymous 2011-09-27 7:33

>>12
Successful attempt at granting ``Failed attempt at granting ``SLACKWARESUPREMACY'' meme status.'' meme status.

Name: Anonymous 2011-09-27 7:55

>>13
Failed attempt at granting ``Successful attempt at granting ``Failed attempt at granting ``SLACKWARESUPREMACY'' meme status.'' meme status.

Name: Anonymous 2011-09-27 14:03

>>14
Successful attempt at granting ``Failed attempt at granting ``Successful attempt at granting ``Failed attempt at granting ``SLACKWARESUPREMACY'' meme status.'' meme status.'' meme status.

Name: Anonymous 2011-09-27 16:40

>>15

you guys really are kings of recursion, eh

Name: Anonymous 2011-09-27 17:28

SLACKWARESUPREMACYSLACKWARESUPREMACYSLACKWARESUPREMACY

Name: Anonymous 2011-09-27 17:30

SLACKWARESUPREMACYSLACKWARESUPREMACYSLACKWARESUPREMACYSLACKWARESUPREMACY

Name: Anonymous 2011-09-27 18:01

GENTOO SUPREMACY.
JOIN THE FUNROLL LOOPS MASTERRACE.
9/10 RICERS LIKE GENTOO

Name: Anonymous 2011-09-27 19:39

>>19
I don't see a Gentoo sine wave.

Name: Anonymous 2011-09-28 1:17

>>20
It was optimized away.

Name: Anonymous 2011-09-28 1:18

>>19
Back to /g/, ``please''!

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