Thread: compiler

  1. #1
    Registered User
    Join Date
    May 2002


    I'm just having a few troubles when building a c++ program. When I loop through the contents of a Vector or string occasionally but consistantly some cout lines which have normal text and a variable show nothing but a new line.

    #include <vector>
    #include <iostream>

    using namespace std;

    void main(){

    //some operations of a vector
    vector vec;
    //output result
    for(int i = 0; i < (int)vec.size();i++){

    cout << "line " << i << vec[i] << endl;

    line 0 hello


    this is just an example but it does happen, could it be my compiler. It is the free borland compiler and uses the bcc32 comand.

    by the way, for your message board (unless you want to be netscape compatible) you could try the editor that you get in hotmail?? to do this go to this site and it has all about how to built it.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    There's probably some bug in your code.. I doubt something as simple as traversal would be screwed up with an STL implementation.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Won't even compile on mine (bcc32). Says:
    Cannot use template 'vector<T,Allocator>' without specifying specialization parameters in function main()
    I changed this
    >vector<char *> vec;
    and it worked, but I don't know anything about vectors so it may be wrong anyway!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    May 2002
    Possibly I'll be trying it on visual C++ later anyway, I'm also having trouble with vectors in that I build a vector <string> but when I assign a value to it becomes constant so if I want to use a string method such as, strcmp(str, vec[i]); I get an invalid call of strcmp(char *, const char *); or strcmp(char*, string);

    Is there any way to solve this??

  5. #5
    Registered User
    Join Date
    May 2002

    STL containers

    One thing to keep in mind is that STL containers are better created with pointers to complex objects. If you don't have a copy operator in your object and STL cintains it, you may inadvertently create empty objects during manipulation. (See Meyer's Effective STL he has a nice explanation).

  6. #6
    Registered User
    Join Date
    Oct 2001
    >strcmp(str, vec[i]);
    If both are strings, I think you can say:
    if (str == vec[i])

    Or if str is a char array then:
    strcmp(str, vec[i].c_str());

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM