Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

‘ostream’ in namespace ‘std’ does not name a type

Tags:

c++

linux

gcc

g++

As the title suggests I'm experiencing a rather odd problem. When I try to compile a sample source code (that uses libotb) I keep getting errors like the one in the title. What is weird is that #include <iostream> is present in the said source/header where the error is reported.

On the other hand if I extract the code from the said file and create a separate source and compile it with g++ <source_file> it works, but if I compile with g++ -I<path_to_libotb_headers> <source_file> I get the same error, although the source file doesn't include anything from said path.

As stated in the below comments, this issue happens with simply

#include <iostream>   

int main                                                                                
{
    std::cerr << "Test";
    return 0;
}
like image 958
skyel Avatar asked Nov 20 '12 10:11

skyel


People also ask

What is std :: ostream?

The std::ostream , the std::istream or the std::iostream are base classes of stream types (e.g. std::stringstream , std::fstream , etc.) in the Standard Library.

What is use of using namespace std in C++?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.


2 Answers

#include <ostream>

should fix it. Under C++11, #include <iostream> is supposed to pull in all of <ostream>, but prior to C++11 you had to do the individual #includes.

like image 140
Pete Becker Avatar answered Oct 06 '22 14:10

Pete Becker


It should be:

int main ()

  • you missed the () :)
like image 42
Luke Avatar answered Oct 06 '22 15:10

Luke