|
-
Sep 8th, 2002, 07:50 PM
#1
Thread Starter
Fanatic Member
vectors
can i make a vector of vectors?
i have text file with blocks
SAY
<text>
RES
<text>
END
I wanna hold as many of these blockes in different vectors...its for a scripting thingy.
like one vector for SAY, but the number of vectors varies on the number of blocks..
or is there a better way to do this?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Sep 8th, 2002, 08:14 PM
#2
Frenzied Member
You CAN make a vector of vectors, but be careful. When you use a template class as a parameter for another template class, you can run into a little problem that gets nearly EVERYONE. Consider:
Code:
vector<vector<int>> vec;
See the error?
Code:
vector<vector<int>> vec;
The compiler will think that you are typing a bit shift operator, instead of templating. To avoid this, simply add a space:
Code:
vector<vector<int> > vec;
No more error.
Z.
-
Sep 8th, 2002, 08:21 PM
#3
Thread Starter
Fanatic Member
oh ok, i see
so how would i use it then?
sorry im new to this
so i can have a variable number of blocks that are seperate. could a linked list also be used? but i guess id have to have a vector of those
not strin vectors, im using
vector<char*> say;
im trying to use string but it complains more and more...heh
Last edited by nabeels786; Sep 8th, 2002 at 08:27 PM.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Sep 8th, 2002, 08:43 PM
#4
Frenzied Member
Originally posted by nabeels786
im trying to use string but it complains more and more...heh
Complains like a mother, doesn't it? =). I had to write my own vector class to use the STL string with a vector.
Z.
-
Sep 8th, 2002, 08:46 PM
#5
Thread Starter
Fanatic Member
oh ok, well ill stick with char* then.
heres where the problem is:
Code:
if(!strcmp(tmpline,"SAY")){
//get everything from SAY to RES
while(strcmp(tmpline,"RES") && !feof(script)){
fgets(tmpline,255,script);
tmpline=trimnl(tmpline);
if(strcmp(tmpline,"RES")){
if(debug)
debugp(tmpline);
say.push_back(tmpline);
}
}
//get everything from RES to END
while(strcmp(tmpline,"END") && !feof(script)){
fgets(tmpline,255,script);
tmpline=trimnl(tmpline);
if(strcmp(tmpline,"END")){
if(debug)
debugp(tmpline);
resp.push_back(tmpline);
}
}
on the push backs
it doesnt actually give an error, but i think you know what i mean
i can use string, but then i get other errors which i cant fix cuz i dunno how
the debugp shows the tmpline fine, so its reading it in correctly fromthe file, but when i list the contents of the vector, its all scrwed up
vector< char * > say;
vector< char * > resp;
are the declarations
thx
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Sep 9th, 2002, 04:09 AM
#6
There is another problem: the nesting level is fixed:
2 levels:
vector <vector <type> >
3 levels:
vector <vector <vector <type> > >
but it's not variable at run-time.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2002, 11:18 AM
#7
Monday Morning Lunatic
Originally posted by Zaei
Complains like a mother, doesn't it? =). I had to write my own vector class to use the STL string with a vector.
Z.
What error was that? I've never had any problems with string and vector
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 9th, 2002, 03:09 PM
#8
Frenzied Member
"<some freakishly long mangled function/object name" has been truncated to 255 characters in the debug information.
Unfortunatly, "freakishly long" usually means ~5 lines in the output window, and there are usually about 5 of the things all together. Makes it a PAIN to find the REAL problems, and it also seems that #pragma warning(disable :<#>) doesnt really help.
Z.
-
Sep 9th, 2002, 03:11 PM
#9
Frenzied Member
Here, this is my build output (punishment?) for trying to declare a vector<string>:
--------------------Configuration: EXEExport - Win32 Debug--------------------
Compiling...
main.cpp
c:\c++\exeexport\main.cpp(10) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_
traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\c++\exeexport\main.cpp(10) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits
<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
main.obj - 0 error(s), 4 warning(s)
Z.
-
Sep 9th, 2002, 03:13 PM
#10
Thread Starter
Fanatic Member
i got mine to work
i guess u do have
#include<vector>
#include<string.h>
using namespace std;
?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Sep 9th, 2002, 03:14 PM
#11
Frenzied Member
Nope, #include <string>.
Z.
-
Sep 9th, 2002, 05:55 PM
#12
Monday Morning Lunatic
Originally posted by Zaei
Here, this is my build output (punishment?) for trying to declare a vector<string>:
Z.
That's a warning, not an error. It means that it couldn't fit the generated symbol into the debug information. I'm sure you can disable it, I do it regularly. Unfortunately my code is archived right now until I get my PC back up and running and get off this damn keyboard. Has taken me about 5 minutes to type this!
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 9th, 2002, 06:31 PM
#13
Frenzied Member
I know its a warning... Thus "it COMPLAINS like..." =). In the end though, when Im working on something with a bit of substance, that output might look like "main.obj - 3 error(s), 44 warning(s)"... And its just a BIT difficult to find those 3 errors in some 200 lines of warning =(.
Z.
-
Sep 9th, 2002, 06:32 PM
#14
Frenzied Member
And you might type faster using the character map =P.
Or maybe the Onscreen Keyboard =P.
Z.
-
Sep 10th, 2002, 07:52 AM
#15
Monday Morning Lunatic
I was just wondering as to why you needed to write your own vector class
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 10th, 2002, 09:28 AM
#16
#pragma warning(disable: whatever)
worked for me with exactly this error...
Look into the compiler/linker options, maybe you can globally disable that error.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 10th, 2002, 09:34 AM
#17
Frenzied Member
Originally posted by parksie
I was just wondering as to why you needed to write your own vector class
It was already written (one of those things to see if I could =).
CornedBee, ill take a look =). It will certainly be nice to not have to remember what vector I am using =).
Z.
-
Sep 11th, 2002, 02:57 AM
#18
I just received a load of books from amazon, one of those recommended to add exactly this line at the top of every file where you use vector<string>. Interestingly it's a game programming book...
If you use AppWizard and it creates a stdafx.h file, put it in there to force the warning off in all files. It's totally useless anyway.
Code:
Valid VC++ syntax.
Jippieh.
No compiler errors
#include "stdafx.h"
This is an error.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 05:53 AM
#19
Thread Starter
Fanatic Member
yeah i have the stdafx.h
i thought you mean to put "Jippieh."
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Sep 11th, 2002, 07:23 AM
#20
Don't look at that code snippet, it's totally unrelated to the thread.
I just remembered the interesting fact that the VC++ compiler ignores everything up to the
#include "stdafx.h"
so I can write what I want there...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 03:04 PM
#21
Frenzied Member
Yeah, that was pretty annoying until I figured it out =).
Z.
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
|