Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ok well i have a prob with cout

Status
Not open for further replies.

iworkingonit

Programmer
Dec 17, 2008
8
0
0
every time i try to use cout in my programs it calls it either an error or a syntax error and i am using microsoft visual c++ 2008 express edition any help neone i am desperate i am trying to learn rele hard and i am having no luck because of the one statement if there is another statemen i can use please tell me
 
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

even this won't work
 
I don't see anything wrong with that.
What errors are you getting?
 
'cout' : undeclared identifier
1>c:\users\admin\documents\visual studio 2008\projects\maybe this one will work\maybe this one will work\sample.cpp(5) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\admin\documents\visual studio 2008\projects\maybe this one will work\maybe this one will work\sample.cpp(3)' was matched
1>Build log was saved at "file://c:\Users\Admin\Documents\Visual Studio 2008\Projects\maybe this one will work\maybe this one will work\Debug\BuildLog.htm
 
Try doing a Build->Clean Solution, then rebuild it again.
If that doesn't work, delete everything and type it in again, maybe there's an invisible character somewhere that's messing things up.
I have 2008 express and it compiles fine on mine.
 
As usually your 1st project must be defined with VS Wizard and code is started from #include "stdafx.h". No such normal VS 2008 stuff in your snippet.
Try again:
File|New|Project
then select Win32 and Win32 Console Application, enter project name and press OK
then insert #include <iostream> in stdafx.h file generated by compiler
then insert using namespace std; after #include "stdafx.h" in the main module and write your helloworld main function then enjoy...

It seems you can't create a console project correctly...
 
the only thing is arkm is that it won't let me use stdafk.h can i change that in the environment variables and if so how do i change them
 
The stdafx.h file is generated by VC++ IDE when precompiled headers mode is in effect (by default). Check Project|Properties then C/C++|Precompiled headers page - /Yu flag if you have cmd line compiler only.
If precompiled headers mode is off then no need in stdafx.h file at all.
 
thank you so much arkm that helps alot so then instead of just <iostream> if no precompiled header but there is one prob if that is true then it calls cout an undeclared identifier
 
Check list:
1. Project: Win32 console application
2. Have #include <iostream>
3. Have using namespace std;
or
Use std::cout
 
well i don't know what happened but it stopped calling it an undeclared idetifier but now iostream.h doesn't work
 
The iostream.h is an old (very old) C++ stream library header. Forget it.
Use <iostream> header only.

 
ok thanks but sometimes if a program that i have tried to find online has that then i tried to replace it with that it makes even more errors i no that it starts from the top and all but well i guess you understand
 
If you have troubles with HelloWorld code in Win32 console application then probably the only medicine: reinstall Visual Studio 2008 Express.
May be better post your code?
 
or you could also post the error messages and see if that tells us anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top