Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
#include<iostream>
int main()
{
    char ch = 'A';
    int num = ch;

    cout << "The ASCII code for " << ch << "is " << num << "\n";
    cout << "Adding 1 to the character code : \n";
    ch = ch + 1;
    num = ch ;
    cout << "The ASCII code for " << ch << "is " << num << "\n";
    return (0);
}     

I get the errors like

ex1.cpp: In function ‘int main()’:
ex1.cpp:6:5: error: ‘cout’ was not declared in this scope
ex1.cpp:6:5: note: suggested alternative:
/usr/include/c++/4.6/iostream:62:18: note:   ‘std::cout’

Guys please correct my mistakes.

share|improve this question

closed as off topic by Tachyons, green7, Rafał Cieślak, hhlp, Thomas Ward Mar 9 '13 at 22:49

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Simply add 'using namespace std' before main function – Tachyons Mar 9 '13 at 17:50
1  
You should ask programming related questions at www.stackoverflow.com, this website is only for Ubuntu-related questions. :) And the above comment is the answer to the question. – green Mar 9 '13 at 17:56
    
@Tachyons thanks :) – prabuksara Mar 9 '13 at 18:01
    
@green7 New to AskUbuntu so sorry :) – prabuksara Mar 9 '13 at 18:05
    
No Problem. Atleast, now you know. – green Mar 9 '13 at 18:06
up vote 2 down vote accepted

Do not add a global using namespace std as other users are saying, this is an extremely bad practice, learn how to use methods and namespaces instead.

cout is not a particular method, std::cout is the method cout from the std namespace and this is the correct way to write methods in C++.

share|improve this answer

Add using namespace std after your include(s).

share|improve this answer
    
Whoops.. Just realized the answer already was in the comments above. – Frederik Spang Mar 9 '13 at 18:06
    
I posted it as comment because this question is offtopic here – Tachyons Mar 9 '13 at 18:11
    
Fair enough! It might get moved anyway. – Frederik Spang Mar 9 '13 at 18:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.