hello people,
its the very first time im doing programming stuff.And i have done nothing so far.I found a booklet in my bookcase,it's about C++.,ts just the first booklet of a serie.
i use visual c++ 2008 express,i did new>file>C++

i used the same codes as in the booklet,here it is

//File Name: Source1.cpp

//This is my first program.
/*I will just make it write something*/

#include <iostream>

int main()
{
	cout << "TEST\n";

	return 0;
}

i added the cpp file into a project because it wasnt compiling if i didnt add it.But when i click the compile it gives an error.it says:

'cout' : undeclared identifier

then i added ":" next to the "cout"
i clicked compile it said:

error C2143: syntax error : missing ';' before '<<'

and i added ";" before "<<" but it keeps telling me that.and there were no ":" next to "cout" on the booklet. what am i gonna do?by the way i dont know nothing about programming,i just follow the instructions.and its a very old booklet,cant reach the author.

hello people,
its the very first time im doing programming stuff.And i have done nothing so far.I found a booklet in my bookcase,it's about C++.,ts just the first booklet of a serie.
i use visual c++ 2008 express,i did new>file>C++

i used the same codes as in the booklet,here it is

//File Name: Source1.cpp

//This is my first program.
/*I will just make it write something*/

#include <iostream>

int main()
{
cout << "TEST\n";

return 0;
}

i added the cpp file into a project because it wasnt compiling if i didnt add it.But when i click the compile it gives an error.it says:

'cout' : undeclared identifier

then i added ":" next to the "cout"
i clicked compile it said:

error C2143: syntax error : missing ';' before '<<'

and i added ";" before "<<" but it keeps telling me that.and there were no ":" next to "cout" on the booklet. what am i gonna do?by the way i dont know nothing about programming,i just follow the instructions.and its a very old booklet,cant reach the author.

Add the line

using namespace std;

after

#include<iostream>

or,use

std::cout<<"Test";

When a compiler says, "Missing/Expected semicolon/operator before whatever", is really an euphemism for the vague meme, "You're doing it wrong!"(not to be rude)

You're missing the std namespace. std::cout << endl; , or after including your templates and classes, using namespace std; which means you wouldn't have to use std::cout .

edit:
Just follow what Zalezog said.

ok i solved the problemand i created an exe.but it just opens and closes so fast,u cant even see the writing.

i added return 0; and added a breakpoint on that line but it keeps doing it.in the visual c++ it runs normal.but when i run the exe it opens and closes

ok i solved the problemand i created an exe.but it just opens and closes so fast,u cant even see the writing.

i added return 0; and added a breakpoint on that line but it keeps doing it.in the visual c++ it runs normal.but when i run the exe it opens and closes

The line just before return 0; add cin.get(); which will mean before it closes you have to press enter... The reason being is that the program currently is told to display something then to exit. By adding cin.get() you're also telling it to wait for you to press enter before exiting. It would also be a good time to warn you again using the lovely system("PAUSE"); line... Don't. http://www.gidnetwork.com/b-61.html

i added it correctly on the line before the "return" line,i compiled builded but it still opens and closes with the debug version. there are two versions of exe one is debug one is release.release one is working properly but debug one is opens and closes.

Rebuild the debug version and it should work fine. Might I add that your first method should be run the program from the Command Prompt, rather than using cin.get(); Since they are technically supposed to be run from the command prompt...it will also allow you to see your output.

Only use cin.get(); if you really must.

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.