• Advertisement
Sign in to follow this  

Visual Studio 2008 Problem

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, i am a beginner learning C++ It has become apperant that there is a compiling problem with the #include <iostream> i tried both of the following and the errors that i got are with them. #include <iostream.h> fatal error C1083: Cannot open include file: 'iostream.h' #include <iostream> error C2447: '{' : missing function header (old-style formal list?) Any Help?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Bradpm
Hey guys, i am a beginner learning C++

It has become apperant that there is a compiling problem with the #include <iostream> i tried both of the following and the errors that i got are with them.

#include <iostream.h>

fatal error C1083: Cannot open include file: 'iostream.h'

#include <iostream>

error C2447: '{' : missing function header (old-style formal list?)

Any Help?

#include <iostream> is correct. Can we see your code?

Share this post


Link to post
Share on other sites
1: #include <iostream>
2:
3:
4: int main();
5: {
6: cout <<"Hello World!\n";
7: return 0;
8: }

Share this post


Link to post
Share on other sites
Quote:
Original post by Bradpm
1: #include <iostream>
2:
3:
4: int main();
5: {
6: cout <<"Hello World!\n";
7: return 0;
8: }
You don't want a semicolon at the end of line 4 there. That's what the error is referring to (Somewhat cryptically)

Share this post


Link to post
Share on other sites
I removed it and now i get 2 errors :S

error C2447: '{' : missing function header (old-style formal list?)
error C2065: 'cout' : undeclared identifier

Share this post


Link to post
Share on other sites
That worked :)

Just that one error left haha :)

error C2447: '{' : missing function header (old-style formal list?)

Here is the code:

#include <iostream>


int main()
{
std::cout <<"Hello World!\n";
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Bradpm
That worked :)

Just that one error left haha :)

error C2447: '{' : missing function header (old-style formal list?)

Here is the code:

#include <iostream>


int main()
{
std::cout <<"Hello World!\n";
return 0;
}
What line does the error refer to? Are you sure that's your exact code?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 : ':'

Share this post


Link to post
Share on other sites
Hey sly, thanks for the explanation :)

How do i change the compiler option :)

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
The source files are C++
I have checked the compiler settings, they are correct.

Share this post


Link to post
Share on other sites
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[])

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement