Jump to content
  • Advertisement
Sign in to follow this  
SL33pY_Kr3W

fstream

This topic is 4353 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
Advertisement
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
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 this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!