locked
Console::WriteLin( S" not compile in vc++2015, please help RRS feed

  • Question

  • dear windows, visual c++ 2015 programers:

      I tried to copy/test a simple code(first example code in the book) visual c++.net by Deitel, on my visual studio 2015 enterprise 32bit , vc++, on my win7
    but I get compile errors(I already modify some setting, but it still not work)
    ---------

    Severity Code Description Project File Line

    Error C2065 'S': undeclared identifier ASimpleProject1 c:\Users\erli89080\documents\visual studio 2015\Projects\ConsoleApplication1test\Welcome.cpp 10

    Severity Code Description Project File Line
    Error (active) identifier "S" is undefined ASimpleProject1 c:\Users\erli89080\Documents\Visual Studio 2015\Projects\ConsoleApplication1test\Welcome.cpp 10

    Error C2059 syntax error: 'string' ASimpleProject1 c:\Users\erli89080\documents\visual studio 2015\Projects\ConsoleApplication1test\Welcome.cpp 10




    Error (active) expected a ')' ASimpleProject1 c:\Users\erli89080\Documents\Visual Studio 2015\Projects\ConsoleApplication1test\Welcome.cpp 10
    ---------------------------------------------------------------------------
    so I checked the web/google search, it look I miss #include <stdafx.h>
    so I include its path at project property 's vc++ directory, include directory;
    the result, of compile, generate more errors.

    please help, eric, thanks a lot in advance

    ----------original program--------------------
    // Fig. 2.16: Welcome.cpp
    // Simple welcome program.
    //#include <stdafx.h>
    #using <mscorlib.dll>

    using namespace System;

    int main()
    {
    Console::WriteLine(S" Welcome to Visual C++ .NET!" );

    return 0;
    }
    -------------------------------------------------------------------
    Tuesday, August 25, 2015 11:45 AM

Answers

  • Drop the S in front of the string literal.

    It's possible that you need a newer book, the S prefix for strings was used for "Managed Extensions for C++" which has deprecated a long time ago.

    • Proposed as answer by Pintu Shukla Tuesday, August 25, 2015 6:15 PM
    • Marked as answer by Shu 2017 Monday, September 7, 2015 8:47 AM
    Tuesday, August 25, 2015 12:05 PM
  • The following was generated by the VS2015 App Wizard for a CLR console application:

    // ConsoleApplication1.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    
    int main(array<System::String ^> ^args)
    {
        Console::WriteLine(L"Hello World");
        return 0;
    }
    

    • Marked as answer by Shu 2017 Monday, September 7, 2015 8:47 AM
    Tuesday, August 25, 2015 12:19 PM

All replies

  • Drop the S in front of the string literal.

    It's possible that you need a newer book, the S prefix for strings was used for "Managed Extensions for C++" which has deprecated a long time ago.

    • Proposed as answer by Pintu Shukla Tuesday, August 25, 2015 6:15 PM
    • Marked as answer by Shu 2017 Monday, September 7, 2015 8:47 AM
    Tuesday, August 25, 2015 12:05 PM
  • The following was generated by the VS2015 App Wizard for a CLR console application:

    // ConsoleApplication1.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    
    int main(array<System::String ^> ^args)
    {
        Console::WriteLine(L"Hello World");
        return 0;
    }
    

    • Marked as answer by Shu 2017 Monday, September 7, 2015 8:47 AM
    Tuesday, August 25, 2015 12:19 PM