Thread: Compiling using g++ and getting errors...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Question Compiling using g++ and getting errors...

    ok so i wrote my code in Borland C++ and everything worked just perfectly...now i have to submit my assignment using sunfire and so i had to compile on linux using this command:

    g++ -c astar.cpp

    and i'm getting like loads of errors...i don't know why this is happening...is it because of compiler differences...

    anyway the most prominent errors are:

    - string was not declared in this scope
    this is when i declare a string like this:

    string something;

    and actually it's about all variable declarations mostly...i don't get i...in one case i pass a float x to a function and when i use it in that function it says that this float is not defined!

    what's going on...can someone help me with proper ways to declare this in the g++ environment...

    Regards,

    Farooq

    Here are some of the errors:

    Code:
    astar.cpp:21: syntax error before `,'
    astar.cpp:84: syntax error before `;'
    astar.cpp:85: `string' was not declared in this scope
    astar.cpp:85: template argument 1 is invalid
    astar.cpp:85: template argument 1 is invalid
    astar.cpp:85: template argument 2 is invalid
    astar.cpp:85: ANSI C++ forbids declaration `CityConnections' with no type
    astar.cpp:90: syntax error before `;'
    astar.cpp:135: `string' was not declared in this scope
    astar.cpp:135: template argument 1 is invalid
    astar.cpp:135: template argument 1 is invalid
    astar.cpp:135: template argument 3 is invalid
    astar.cpp:135: ANSI C++ forbids declaration `CityNode' with no type
    astar.cpp:217: `string' was not declared in this scope
    astar.cpp:217: parse error before `,'
    astar.cpp: In method `void Astar::readFile(char *)':
    astar.cpp:140: `string' undeclared (first use this function)
    astar.cpp:140: (Each undeclared identifier is reported only once
    Last edited by alvifarooq; 09-24-2004 at 08:20 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    ok so i think it was something to do with the .h in the include statements...apparently i can use .h with everything except string iostream etc etc...

    anyway thanks...ill post here if i get more errors...

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    String is in the standard namespace. Give string it's scope resolution.. std::string. You could place using namespace std; after the include files <string> <iostream> etc.

Popular pages Recent additions subscribe to a feed