What is wrong with this code?

E

eli m

I am using the dev c++ compiler and i have this code:

#include <iostream>
int main ()
{
int cmd = 0;
cout << "Type in help for a list of commands";
while (cmd == 0) {
cout << "Type in a function:";
cin >> function;
}
}

And i got these errors:

In function `int main()':

5 `cout' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)

8 `cin' undeclared (first use this function)

8 `function' undeclared (first use this function)

Why am i getting these errors? How am i supposed to do this in c++?
 
I

Ian Collins

eli said:
I am using the dev c++ compiler and i have this code:

#include <iostream>
int main ()
{
int cmd = 0;
cout << "Type in help for a list of commands";
while (cmd == 0) {
cout << "Type in a function:";
cin >> function;
}
}

And i got these errors:

In function `int main()':

5 `cout' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)

8 `cin' undeclared (first use this function)

8 `function' undeclared (first use this function)

Why am i getting these errors? How am i supposed to do this in c++?

Which book are you using that doesn't tell you cout and cin are in the
std namespace?

Why haven't you declared function?
 
E

eli m

Which book are you using that doesn't tell you cout and cin are in the

std namespace?



Why haven't you declared function?

Can you explain in more detail please.
 
M

marsonmao

eli mæ–¼ 2013å¹´3月5日星期二UTC+8上åˆ8時12分39秒寫é“:
cout << "Type in help for a list of commands";
cout << "Type in a function:";
5 `cout' undeclared
8 `cin' undeclared (first use this function)

cout and cin are functions defined in namespace std,
so you should write as "std::cout" and "std::cin".
cin >> function;
in this line you havent declared what "function" is.
 
E

eli m

eli mæ–¼ 2013å¹´3月5日星期二UTC+8上åˆ8時12分39秒寫é“:







cout and cin are functions defined in namespace std,

so you should write as "std::cout" and "std::cin".




in this line you havent declared what "function" is.

Thank you I figured it out!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top