Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AndreTheGiant

file input ?

This topic is 5548 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

Ive been looking for a way to do some file input in c++. If i google it, i end up with about a million different ways to do it, but none of them are what i want. Most of them use c-style strings ( char* ), and most of them read one character from the file at a time using getch() or something. I want a method that uses std::string instead of an array of characters,and i want to be able to read a whole line at a time. Ive been looking at fstream , and within that, ifstream. It provides a getline() function that reads a whole line, but it stores it in a c-style string, not an std::string. can someone post the 3 or 4 lines of code needed to acheive what im trying to do? Im sure it exists but i just cant find an example. tanks! [edited by - AndreTheGiant on August 9, 2003 5:30:10 PM] [edited by - AndreTheGiant on August 9, 2003 5:30:37 PM]

Share this post


Link to post
Share on other sites
Advertisement
ok sure make me look stoopid

so what headers did you include for that to work? and what about the using declaration?
I dont like to say

using namespace std;

I like to specifiy each thing separately like this:

include
using std::cout;
using std::endl;



thanks!

Share this post


Link to post
Share on other sites
quote:
Original post by AndreTheGiant
ok sure make me look stoopid

so what headers did you include for that to work? and what about the using declaration?
I dont like to say

using namespace std;

I like to specifiy each thing separately like this:

include
using std::cout;
using std::endl;



thanks!



#include <fstream>
using namespace std;

ostream fout;
fout.open("file");
fout << data;
fout.close();

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!