Results 1 to 21 of 21

Thread: vectors

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    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?

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  3. #3

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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?

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  5. #5

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  8. #8
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    "<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.

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  10. #10

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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?

  11. #11
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Nope, #include <string>.

    Z.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  13. #13
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    And you might type faster using the character map =P.

    Or maybe the Onscreen Keyboard =P.

    Z.

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    #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.

  17. #17
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  19. #19

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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?

  20. #20
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  21. #21
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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
  •  



Click Here to Expand Forum to Full Width