Answer» Hi all,
I am trying to read from a .txt file into a 2d string vector using tabs(\t) as a delim
eg: the text file will contain
2 4 2 23 1 12 3 3 2 3 42 1 23 1 32 2 1 2 3 4 5
so my vector which ill call figures should be
figures[0][0] = 2 figures[0][2] = 2 figures[1][0] = 3 figures[2][0] = 32
and so on
for some reason when i read into my vector it all goes into figures[0][0] which is pointless when i want to manipulat data.
ive pasted the relivant code below.
Any help would be greatly appreciated.
ifstream inFile; vector > figures; string current;
inFile.open(text.txt);
while (getline( inFile, current, '\t' ) ){ figures.push_back ( vector() ); figures.push_back (token); i++; }//while cout << figures[0][0] << endl;Not much help probably, but when playing with graphic rendering for C++ I usually work with bit maps, which are easier to manage than reading in ascii from text file and vector rendering it. What type of application is this going to be a user input/output type of application or a game?
I have also had issues trying to get graphics to work for say Borland 5 while MS Visual C++ 6.0 ran the PROGRAM without problems.First, put your code in code blocks. that's what they are for.
Second, include the full code. People trying to help you would appreciate not having to do googles up to ying yang to find out what NEEDS to be included at the top of the file, not to mention it's not even in it's own routine, it's just a bunch of code with no context.
Last, i wasn't able to even get it to compile, after about 15 MINUTES of searching I really shouldn't have bothered with, since the way you use "getline" didn't work on any of the compilers I tried.
Lastly:
Code: [Select] figures.push_back ( vector<string>() ); figures.push_back (token); This adds a new string vector to the figures vector, and then adds "token" to the end of that. but you never initialized token.
Obviously this is not the code you are actually using, since it would take quite a bit of effort to get it compiled.
Quote from: DaveLembke on December 06, 2010, 08:55:47 PM Not much help probably, but when playing with graphic rendering for C++ I usually work with bit maps, which are easier to manage than reading in ascii from text file and vector rendering it. What type of application is this going to be a user input/output type of application or a game?
I have also had issues trying to get graphics to work for say Borland 5 while MS Visual C++ 6.0 ran the program without problems.
he didn't even hint at graphics of any kind...
|