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

19,559

Solution 1

#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.

Solution 2

It should be:

int main ()

  • you missed the () :)

Solution 3

Verify that your includes all closed their namespaces -- your include may accidentally be declared in a namespace if a previous header did not close its namespaces.

You can also attempt to locate this problem by moving the std includes earlier in the include list.

Share:
19,559
skyel
Author by

skyel

void

Updated on June 26, 2022

Comments

  • skyel
    skyel almost 2 years

    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;
    }