Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Basic string help -- Did I step into the Twilight Zone?

Basic string help -- Did I step into the Twilight Zone?

Scheduled Pinned Locked Moved ATL / WTL / STL
c++helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xpnctoc
    wrote on last edited by
    #1

    Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:

    #include <string>
    #include "stdafx.h"
    int _tmain(int argc, _TCHAR* argv[])
    {
    std::string s = " ";
    printf(s);

    return 0;
    }

    ...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:

    #include <string>
    #include "stdafx.h"
    using namespace std;
    int _tmain(int argc, _TCHAR* argv[])
    {
    string s = " ";
    printf(s);

    return 0;
    }

    ...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.

    J S X 3 Replies Last reply
    0
    • X Xpnctoc

      Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:

      #include <string>
      #include "stdafx.h"
      int _tmain(int argc, _TCHAR* argv[])
      {
      std::string s = " ";
      printf(s);

      return 0;
      }

      ...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:

      #include <string>
      #include "stdafx.h"
      using namespace std;
      int _tmain(int argc, _TCHAR* argv[])
      {
      string s = " ";
      printf(s);

      return 0;
      }

      ...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.

      J Offline
      J Offline
      jk chan
      wrote on last edited by
      #2

      you cannot do printf( s) , instead you can do like printf( s.c_str() ) or cout << s ( make sure that yo include iostream ).

      If u can Dream... U can do it

      1 Reply Last reply
      0
      • X Xpnctoc

        Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:

        #include <string>
        #include "stdafx.h"
        int _tmain(int argc, _TCHAR* argv[])
        {
        std::string s = " ";
        printf(s);

        return 0;
        }

        ...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:

        #include <string>
        #include "stdafx.h"
        using namespace std;
        int _tmain(int argc, _TCHAR* argv[])
        {
        string s = " ";
        printf(s);

        return 0;
        }

        ...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        The precompiled header (stdafx.h) should always be the first header included. Also dump the printf. Try code like this:

        #include "stdafx.h" // Precompiled header should always be first.
        #include <iostream> // We'll use cout instead of printf.
        #include <string>
         
        int _tmain(int argc, _TCHAR* argv[])
        {
            using namespace std;
            string s = "Hello, world!";
            cout << s << endl;
         
            return 0;
        }

        Steve

        1 Reply Last reply
        0
        • X Xpnctoc

          Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:

          #include <string>
          #include "stdafx.h"
          int _tmain(int argc, _TCHAR* argv[])
          {
          std::string s = " ";
          printf(s);

          return 0;
          }

          ...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:

          #include <string>
          #include "stdafx.h"
          using namespace std;
          int _tmain(int argc, _TCHAR* argv[])
          {
          string s = " ";
          printf(s);

          return 0;
          }

          ...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.

          X Offline
          X Offline
          Xpnctoc
          wrote on last edited by
          #4

          Re-ordering the #includes did the trick. I had read about the use of printf/cout but I hadn't gotten to that point since I couldn't even get my variable declaration to compile. Thanks for the pointers.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups