Sign in to follow this  

fstream

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this