By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

output to a file

P: n/a
If I want to get input from a file I use:

#include <fstream>

int main(){

ifstream input("file.in",ios::in);

int x;
input >> x;

}

What about if I want to output to a file?

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Gaijinco wrote:
If I want to get input from a file I use:

#include <fstream>

int main(){

ifstream input("file.in",ios::in);
ios::in is not necessary.

int x;
input >> x;

}

What about if I want to output to a file?


Very similar

int main()
{
ofstream output("file.out");
int x = 42;
outupt << x;
}

Basically use ofstream instead of ifstream and << instead of >>.

john
Nov 22 '05 #2

P: n/a
In article <3H****************@newsfe1-gui.ntli.net>,
John Harrison <jo*************@hotmail.com> wrote:
Gaijinco wrote:
If I want to get input from a file I use:

#include <fstream>

int main(){

ifstream input("file.in",ios::in);


ios::in is not necessary.

int x;
input >> x;

}

What about if I want to output to a file?


Very similar

int main()
{
ofstream output("file.out");
int x = 42;
outupt << x;
}

Basically use ofstream instead of ifstream and << instead of >>.


Gaijinco, PLEASE get yourself a good reference.
See http://www.comeaucomputing.com/booklist for some suggestions.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 22 '05 #3

P: n/a

Gaijinco, PLEASE get yourself a good reference.
See http://www.comeaucomputing.com/booklist for some suggestions.


Also there are good C++ standard library references on the internet. I
like http://www.dinkumware.com/refxcpp.html.

john
Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.