I'm I using terminal in ubuntu. I've installed g++ package for compiling c++ programs. But if I try to compile a program, it is giving an error that 'cout is not declared in this scope', even though I've included iostream header file. What should I do??
            Asked
            
        
        
            Active
            
        
            Viewed 5,910 times
        
    -3
            
            
        - 
                    Post a small example of what you are doing. – drescherjm Mar 29 '14 at 02:19
- 
                    How is iostream included? Is it with the `<>` symbols? – CPlusPlus OOA and D Mar 29 '14 at 02:21
- 
                    5Did you do `#include`? – ikh Mar 29 '14 at 02:21
- 
                    Thank you a lot... it's working by putting std::cout instead of just cout... – Uttam Singapura Mar 29 '14 at 02:36
- 
                    2You forgot to read your C++ book. – Lightness Races in Orbit Mar 29 '14 at 02:48
3 Answers
2
            
            
        Read in more detail about namespaces in c++. cout happens to be in the namespace called std.
After declaring your headers you can dousing namespace std; and you don't have to use std::cout every time and use only cout, but that isn't suggested. instead you could declare only what you need. 
ex: using std::cout; using std::cin; using std::string; that way you don't have to use std::cout everywhere in your code and use only cout or cin
 
    
    
        Community
        
- 1
- 1
 
    
    
        Udit Mukherjee
        
- 687
- 5
- 20
-1
            
            
        Maybe you don't have build-essential ? It's mandatory in order to compile correctly on ubuntu.
 
    
    
        Ulamspi
        
- 16
- 2
- 
                    @Ulamspi: If he has installed the `g++` package, then he has `libstdc++` already, as it is a dependency of `g++`; `build-essentials` isn't an additional requirement (although `build-essentials` is nice as it includes other useful tools). It is also not mandatory to have `build-essentials` to compile software with gcc. – Jason C Mar 29 '14 at 02:57
 
    