Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ios' : is not a class or namespace name

Tags:

c++

file

iostream

I am trying to write a matrix to a file with the above code. But i got the following error: 'ios' : is not a class or namespace name. My code:

std::ofstream myfile;
myfile.open ("C:/Users/zenitis/Desktop/bots/Nova/data/ownStatus.txt", ios::out | ios::app);               

for (int i = 0; i< 21; i++){
    myfile << featureMatrix[i] << "          ";
}
myfile << "\n";
myfile.close();

Any idea about this problem??

like image 940
Jose Ramon Avatar asked Sep 22 '12 22:09

Jose Ramon


2 Answers

ios is a member of std. That is, you want to use one of the following approaches to refer to it:

using namespace std; // bad
using std::ios;      // slightly better

int main() {
    std::ofstream myFile("name", std::ios::app); // best
}

BTW, you can open() the std::ofstream directly in the constructor. Also, for std::ofstream the flag std::ios_base::out (the opening flags are actually defined in std::ios's base class std::ios_base) is added automatically.

like image 153
Dietmar Kühl Avatar answered Nov 04 '22 07:11

Dietmar Kühl


It is actually std::ios::out.

like image 44
Cole Tobin Avatar answered Nov 04 '22 08:11

Cole Tobin