Syntax error on visual C++ 2008

Could anyone tell me why I am getting syntax error ? I just copied below code from book and tried to run on visual c++ 2008... but I am getting syntax error but it looks exactly same as book..

#include "stdafx.h"

using namespace System;
using namespace System::Text;

int main(array<System::String ^> ^args)
{
String ^m_Lang="C++";
int m_Y=2005;

Console::WriteLine("This is visual {0} {1}," m_Lang,m_Y);
Console::WriteLine(String::Concat("This is Visual," m_Lang, "," m_Y));
Console::WriteLine("This is Visual"+m_Lang+" " +m_Y);

Console::WriteLine(Math::PI.ToString("#.###"));
StringBuilder ^m_Builder=gcnew StringBuilder("This is visual c++");
m_Builder->Append(m_Y);
Console::WriteLine(m_Builder);

return 0;
}

ERROR :
1>StringConcat_Example.cpp
1>.\StringConcat_Example.cpp(13) : error C2146: syntax error : missing ')' before identifier 'm_Lang'
1>.\StringConcat_Example.cpp(13) : error C2059: syntax error : ')'
1>.\StringConcat_Example.cpp(14) : error C2146: syntax error : missing ')' before identifier 'm_Lang'
1>.\StringConcat_Example.cpp(14) : error C2059: syntax error : ')'
1>.\StringConcat_Example.cpp(15) : error C2045: 'Console' : label redefined
1>.\StringConcat_Example.cpp(14) : error C3861: 'WriteLine': identifier not found
1>.\StringConcat_Example.cpp(15) : error C3861: 'WriteLine': identifier not found
Last edited on
This is c++/cli language, not c++. It is only available in Microsoft world, make sure you really want to learn this.

Create a new c++/cli project for this or use /clr compiler switch.
Hi, Thank you for your reply. What do you mean if I want to learn this ? C++/CLI is not C++ ? Or nobody uses this C++/CLI ? Thanks
What do you mean if I want to learn this ?

Decide what language you want to learn, and learn it.

C++/CLI is not C++ ?

True.

Or nobody uses this C++/CLI ?

False.

Topic archived. No new replies allowed.