namespace std

when i include the line:
[code]
using namespace std;
[/code]
i get declaration syntax error
«1

Comments

  • : when i include the line:
    : [code]
    : using namespace std;
    : [/code]
    : i get declaration syntax error

    i know Turbo C/C++, which doesnt know what a namespace is, and thus generate such error.
  • : : when i include the line:
    : : [code]
    : : using namespace std;
    : : [/code]
    : : i get declaration syntax error
    :
    : i know Turbo C/C++, which doesnt know what a namespace is, and thus generate such error.
    :
    who makes the best API? do others support ASM as does Turbo C?
  • : : : when i include the line:
    : : : [code]
    : : : using namespace std;
    : : : [/code]
    : : : i get declaration syntax error
    : :
    : : i know Turbo C/C++, which doesnt know what a namespace is, and thus generate such error.
    : :
    : who makes the best API? do others support ASM as does Turbo C?
    :

    If you are using Turbo C++, you probably should dump it. It is an ancient compiler and won't support many features of the language. I think most support ASM.
    [italic][blue]Just my 2 bits[/blue][italic]

  • : when i include the line:
    : [code]
    : using namespace std;
    : [/code]
    : i get declaration syntax error
    :

    Instead of
    [code]
    using namespace std;
    [/code]
    use
    [code]
    using namespace std::cout; // or what ever you're trying to use
    [/code]
    and see if that does anything different.
  • : : when i include the line:
    : : [code]
    : : using namespace std;
    : : [/code]
    : : i get declaration syntax error
    : :
    :
    : Instead of
    : [code]
    : using namespace std;
    : [/code]
    : use
    : [code]
    : using namespace std::cout; // or what ever you're trying to use
    : [/code]
    : and see if that does anything different.
    [purple]that does nothing!

    the problem is the compiler doesnt know what a [blue]namespace[/blue] is. thus the [blue]using[/blue] keyword may also is unknown. since there is no [blue]namespace[/blue], [blue]std[/blue] shouldn't also be there. so all those three words are unknown to the compiler. these generates error.
    [/purple]
  • : : : when i include the line:
    : : : [code]
    : : : using namespace std;
    : : : [/code]
    : : : i get declaration syntax error
    : : :
    : :
    : : Instead of
    : : [code]
    : : using namespace std;
    : : [/code]
    : : use
    : : [code]
    : : using namespace std::cout; // or what ever you're trying to use
    : : [/code]
    : : and see if that does anything different.
    : [purple]that does nothing!
    :
    : the problem is the compiler doesnt know what a [blue]namespace[/blue] is. thus the [blue]using[/blue] keyword may also is unknown. since there is no [blue]namespace[/blue], [blue]std[/blue] shouldn't also be there. so all those three words are unknown to the compiler. these generates error.
    : [/purple]
    :
    [green]
    okay, helps to know these things, thank you
    [/green]
  • why do you need to use:
    [code]
    using namespace std;
    [/code]
    thanks
  • : why do you need to use:
    : [code]
    : using namespace std;
    : [/code]
    :
    it is in all of the code i see on this um board
  • Which compiler do you use?
  • : why do you need to use:
    : [code]
    : using namespace std;
    : [/code]
    : thanks
    [purple]
    a namespace is used to localize variables, functions and classes. it gathers all of these to avoid name collision. so same name can be used for functions, variables and/or classes of different namespaces.

    u know, there are functions like [blue]printf()[/blue], [blue]abs()[/blue], [blue]tolower()[/blue]; objects like [blue]cin[/blue], [blue]cout[/blue] etc. not only these, but the entire C++ library is kept in [blue]std[/blue] namespace. that is why that line is written at the start of almost every program - they are then [red]visible[/red] to ur program. so u can define ur own namespace where u can define another [blue]cin[/blue], [blue]cout[/blue], [blue]printf()[/blue], [blue]abs()[/blue] etc - no name collision occurs, unless u [red]visible[/red] both of them in the same block of code.
    [/purple]
  • : : why do you need to use:
    : : [code]
    : : using namespace std;
    : : [/code]
    : :
    : it is in all of the code i see on this um board
    :
    [blue]
    I personally wouldnt use that. The std namespace
    is huge-and that line would include all of the
    std namepace-unessarily making your program bigger.
    (unless your going to use alot of std, then go for it.)

    I would use simular to [green]std::cout[/green] instead.
    This is only my opinion, though.
    [/blue]
  • : : : why do you need to use:
    : : : [code]
    : : : using namespace std;
    : : : [/code]
    : : :
    : : it is in all of the code i see on this um board
    : :
    : [blue]
    : I personally wouldnt use that. The std namespace
    : is huge-and that line would include all of the
    : std namepace-unessarily making your program bigger.
    : (unless your going to use alot of std, then go for it.)
    :
    : I would use simular to [green]std::cout[/green] instead.
    : This is only my opinion, though.
    : [/blue]
    :


    Using it shouldn't affect program size, unless you have a really crappy linker/compiler.
  • [green]I'm a lazy typer -- so I always code "using namespace std" instdad of specifying everything that my program actually uses. In the end, it doesn't make a hill of difference to the compiler. The only good thing I's seen in namespaces is to limit the scope of objects -- you can have objects in two different namespaces with the same name, just like you can have objects in two different classes or structures with the same name. Other than that, namespaces do nothing at all for c++ programs. And linkers know nothing about namespaces. All the linker knows about are *.obj and *.lib files (on MS-DOS/MS-Windows os) or *.o and *.a on *nix. At that point, the linker is the same for both C (where namespaces are unknown) and C++ programs. [/green]

  • : : : when i include the line:
    : : : [code]
    : : : using namespace std;
    : : : [/code]
    : : : i get declaration syntax error
    : :
    : : i know Turbo C/C++, which doesnt know what a namespace is, and thus generate such error.
    : :
    : who makes the best API? do others support ASM as does Turbo C?
    :

    I don't think it's a question of "API". It's who makes a standards-conforming compiler. And most modern compilers are very standards-compliant. Turbo 4.5 is really old.

    If you need a free compiler, look into GNU g++.

    Finally, asm is not standard C++ but is supported by many compilers (either via the asm command, or _asm or __asm).

    Matt.

  • ...

    : not only these, but the entire C++ library is kept in [blue]std[/blue] namespace. that is why that line is written at the start of almost every program - they are then [red]visible[/red] to ur program.


    That depends on whether you want to bring all those names into scope. Using a [blue]using namespace std;[/blue] statement at the top of a header file is generally recognized as bad coding practice. At the limit, it may be used at the top of .cpp file (and thus visible only within that file).

    Matt.

    PS - Instant message vernacular (e.g., "u r gr8") makes your posts look sort of silly, at least 2 me. (:

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories