Visual Studio 2008 Problem
What compiler are you using? I assume it's Visual Studio, but what version? The code you've posted doesn't have any errors in it.
I had a hunch and I thought I'd try something, and indeed it seems that you are using a .c extension on the source filename instead of .cpp, or you have the compiler option "Compile file as .c" enabled.
D:\Temp>cl hello.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
D:\Temp>hello
Hello World!
D:\Temp>ren hello.cpp hello.c
D:\Temp>cl hello.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello.c
C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\cstdio(25) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\cstdio(25) : error C2059: syntax error : ':'
D:\Temp>cl hello.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
D:\Temp>hello
Hello World!
D:\Temp>ren hello.cpp hello.c
D:\Temp>cl hello.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello.c
C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\cstdio(25) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\cstdio(25) : error C2059: syntax error : ':'
First of all, is your source file .cpp or .c? If .c, change to .cpp.
The compiler option would have been set to C++ code by default, but if you want to check it, go to the project properties, select Configuration Properties > C/C++ > Advanced and make sure that "Compile As" is set to "Compile as C++ Code".
The compiler option would have been set to C++ code by default, but if you want to check it, go to the project properties, select Configuration Properties > C/C++ > Advanced and make sure that "Compile As" is set to "Compile as C++ Code".
Hmm strange problem.
First put
using namespace std;
after
#include <iostream>
so you can only type
cout << "fgsdg";
instead of
std::cout << "rfasdf";
and use this as main
int main (int argc, char* args[])
First put
using namespace std;
after
#include <iostream>
so you can only type
cout << "fgsdg";
instead of
std::cout << "rfasdf";
and use this as main
int main (int argc, char* args[])
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement