# fstream

## Recommended Posts

Hi, I need some help with a few errors I've never encountered before please: 8 ios' has not been declared 8 out' undeclared (first use this function) 8 ios' has not been declared 8 binary' undeclared (first use this function) And the code:
//test
#include<iostream>
#include<fstream>

int main()
{
std::ofstream file;
file.open( "SuperText.txt", ios::out|ios::binary );

file<<"Superwoot";

file.close();

return 1;
}


I have no idea how to fix somethign like this or work around it. Any help would be appreciated.

##### Share on other sites
I'm not 100% sure, but ios is part of std, so either placing an std:: before each or declaring the std namespace should fix your problem, i.e 'using namespace std;'
Secondly, shouldn't you be returning 0 instead of 1?

##### Share on other sites
Awsome, that did it.

Is returning 0 some sort of unspoken rule, or will any arbitrary number work fine? I use 1 because I thought it's like saying "O.K. Everything went well," as opposed to returning 0.

##### Share on other sites
0 is the o.k signal. 1 means that something went wrong I'm pretty sure.

[Edited by - Sol462 on July 20, 2006 9:24:17 PM]

##### Share on other sites
expanding:
0 is "OK"
>0 is an error.
This is due to the fact that your program can run or exit with an error.
If it runs, who cares why it worked.
If if errors out there are many errors that you may want to report, so having
everything but 0 be an error allows for "magic number" error codes you can return.
ie.
you could return 1 on a file not found, 2 on a file not accessable...etc.

##### Share on other sites
The main use of returning integers from your program is so that the shell you ran it from can do something with the output.

##### Share on other sites
As a special case, main implicitly returns 0 if it reaches the end. This is well-defined and standard. I argue that you should not explicitly return it, because there's no sense adding extra code to mark "everything went as expected", because - well - it's *expected*. Thus the extra statement doesn't add any meaning to the program.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627642
• Total Posts
2978354

• 10
• 12
• 22
• 13
• 33