1
votes

I'm trying to learn c++ but a simple method like "cout" and "cin" does not exist this is my code:

#include "stdafx.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
    cout>>"hello";
    return 0;
}

there is an error that says "error C2065: 'cout' : undeclared identifier"

and "IntelliSense: identifier "cout" is undefined"

4
Your angle brackets are backwards. Try std::cout << "hello". - Bill Carey
cout is in the std namespace. Try std::cout << "hello"; - Praetorian
You're missing std:: and you mixed up >> and <<. - Rapptz
I just open a project in visual studio 2012. I only added the: cout<<"hello"; - user2302416
@user2302416: Yes, and that's why it's not working. Change cout<<"hello"; to std::cout << "hello"; -- or, better yet, std::cout << "hello\n";. You could drop the std:: by adding using namespace std;; you'll see a lot of code that does that, but it's often considered to be a bad habit. - Keith Thompson

4 Answers

8
votes

cout is declared in the std namespace:

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "hello";
    return 0;
}

You're also doing it wrong. Note how I have the angle brackets aboove.

1
votes

Add #include <iostream> to stdafx.h. I was having trouble with that and it worked for me.

0
votes

Adding using namespace std; may help, and also do cout << "hello" not >>.

0
votes

cout is in std so you to have use using namespace std. And for cout operator is like <<. >> this is for input i.e cin.

#include "stdafx.h";
#include "iostream";
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    cout<<"hello";
    system("pause");
    return 0;
}