Jose Ramon
Jose Ramon

Reputation: 5444

'ios' : is not a class or namespace name

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??

Upvotes: 6

Views: 19174

Answers (2)

Cole Tobin
Cole Tobin

Reputation: 9429

It is actually std::ios::out.

Upvotes: 6

Dietmar K&#252;hl
Dietmar K&#252;hl

Reputation: 153792

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.

Upvotes: 17

Related Questions