std::cout << "sdfsdf" in MS Visual Studio 2005

Discussion in 'C++' started by ek, Dec 23, 2006.

  1. ek

    ek Guest

    I thought that the syntax for c++ in either winXP or linux was the
    same.

    In Ubuntu linux it works fine if I write:

    #include <string>
    using namespace std;

    int main()
    {
    string bb = "fff";
    std::cout << bb;
    return 0;

    }

    But in winXP in MS Visual Studio 2005 'cout' is not recognized in 'std'

    I also have to declare a string like: std::string s = "ffff". Why does
    'using namespace std' not work in winXP.

    What are there reason for this and are there many cases where C++
    syntax in linux is not compatible with C++ syntax for MS Visual Studio?
     
    ek, Dec 23, 2006
    #1
    1. Advertising

  2. ek

    Pete Becker Guest

    ek wrote:
    > I thought that the syntax for c++ in either winXP or linux was the
    > same.
    >
    > In Ubuntu linux it works fine if I write:
    >
    > #include <string>
    > using namespace std;
    >
    > int main()
    > {
    > string bb = "fff";
    > std::cout << bb;
    > return 0;
    >
    > }
    >
    > But in winXP in MS Visual Studio 2005 'cout' is not recognized in 'std'
    >
    > I also have to declare a string like: std::string s = "ffff". Why does
    > 'using namespace std' not work in winXP.
    >
    > What are there reason for this and are there many cases where C++
    > syntax in linux is not compatible with C++ syntax for MS Visual Studio?
    >


    #include <iostream>

    --

    -- Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." (www.petebecker.com/tr1book)
     
    Pete Becker, Dec 23, 2006
    #2
    1. Advertising

  3. ek

    fireflyc Guest

    Pete Becker wrote:
    > ek wrote:
    > > I thought that the syntax for c++ in either winXP or linux was the
    > > same.
    > >
    > > In Ubuntu linux it works fine if I write:
    > >
    > > #include <string>
    > > using namespace std;
    > >
    > > int main()
    > > {
    > > string bb = "fff";
    > > std::cout << bb;
    > > return 0;
    > >
    > > }
    > >
    > > But in winXP in MS Visual Studio 2005 'cout' is not recognized in 'std'
    > >
    > > I also have to declare a string like: std::string s = "ffff". Why does
    > > 'using namespace std' not work in winXP.
    > >
    > > What are there reason for this and are there many cases where C++
    > > syntax in linux is not compatible with C++ syntax for MS Visual Studio?
    > >

    >
    > #include <iostream>
    >
    > --
    >
    > -- Pete
    > Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    > Author of "The Standard C++ Library Extensions: a Tutorial and
    > Reference." (www.petebecker.com/tr1book)


    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
    .......
    }
     
    fireflyc, Dec 23, 2006
    #3
  4. ek

    ek Guest

    fireflyc skrev:
    > Pete Becker wrote:
    > > ek wrote:
    > > > I thought that the syntax for c++ in either winXP or linux was the
    > > > same.
    > > >
    > > > In Ubuntu linux it works fine if I write:
    > > >
    > > > #include <string>
    > > > using namespace std;
    > > >
    > > > int main()
    > > > {
    > > > string bb = "fff";
    > > > std::cout << bb;
    > > > return 0;
    > > >
    > > > }
    > > >
    > > > But in winXP in MS Visual Studio 2005 'cout' is not recognized in 'std'
    > > >
    > > > I also have to declare a string like: std::string s = "ffff". Why does
    > > > 'using namespace std' not work in winXP.
    > > >
    > > > What are there reason for this and are there many cases where C++
    > > > syntax in linux is not compatible with C++ syntax for MS Visual Studio?
    > > >

    > >
    > > #include <iostream>



    The problem was that I typed 'using namespace std;' in a header file.
    It seems that this is a wrong use and it should be typed in each source
    file.
     
    ek, Dec 23, 2006
    #4
  5. ek

    David Harmon Guest

    On 23 Dec 2006 06:21:34 -0800 in comp.lang.c++, "ek" <>
    wrote,
    >The problem was that I typed 'using namespace std;' in a header file.
    >It seems that this is a wrong use and it should be typed in each source
    >file.


    No, that is not the problem; there is no header file in your example in
    which you could have typed the using directive. The problem as others
    have noted is the missing #include <iostream>
     
    David Harmon, Dec 23, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pmb

    std::cout vs cout

    Pmb, Jun 2, 2004, in forum: C++
    Replies:
    2
    Views:
    4,436
    Leor Zolman
    Jun 2, 2004
  2. rockdale
    Replies:
    1
    Views:
    666
    Juan T. Llibre
    Aug 23, 2006
  3. Stefan Ram

    Re: cout vs std::cout

    Stefan Ram, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    504
  4. saurabh29789

    Sending std::cout to std::cout !!

    saurabh29789, Jun 11, 2009, in forum: C++
    Replies:
    1
    Views:
    305
    Harald Finster
    Jun 11, 2009
  5. saurabh29789

    Sending std::cout to std::cout

    saurabh29789, Jun 11, 2009, in forum: C++
    Replies:
    2
    Views:
    353
    Rolf Magnus
    Jun 12, 2009
Loading...

Share This Page