Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

file help?

I'm new to the fstream and C++ in general so I need some help. I'm writing a simple program that should accept an input file and copy the data to an output file. I used instream >> ch; so that the stream will send one char at a time and then I wrote string str; str += ch; This should concatinate all the chars into that string right? And if it does won't I be able to send that string down the outstream into the output file? I think that maybe there are some general rules that I don't understand about fstream objects and that kind of thing. My book is little help so any help from you would be appreciated.

Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    [b][red]This message was edited by stober at 2003-2-28 14:39:2[/red][/b][hr]
    : I'm new to the fstream and C++ in general so I need some help. I'm writing a simple program that should accept an input file and copy the data to an output file. I used instream >> ch; so that the stream will send one char at a time and then I wrote string str; str += ch; This should concatinate all the chars into that string right? And if it does won't I be able to send that string down the outstream into the output file? I think that maybe there are some general rules that I don't understand about fstream objects and that kind of thing. My book is little help so any help from you would be appreciated.
    :

    [blue]If you concantinate the contents of the entire file into one big string and then write it back out the line separators will not be preservered. You need to do that one line at a time. use std::getline(instream, str) to read a whole line at once. [/blue]


  • deep_seekerdeep_seeker Member Posts: 15
    : [b][red]This message was edited by stober at 2003-2-28 14:39:2[/red][/b][hr]
    : : I'm new to the fstream and C++ in general so I need some help. I'm writing a simple program that should accept an input file and copy the data to an output file. I used instream >> ch; so that the stream will send one char at a time and then I wrote string str; str += ch; This should concatinate all the chars into that string right? And if it does won't I be able to send that string down the outstream into the output file? I think that maybe there are some general rules that I don't understand about fstream objects and that kind of thing. My book is little help so any help from you would be appreciated.
    : :
    :
    : [blue]If you concantinate the contents of the entire file into one big string and then write it back out the line separators will not be preservered. You need to do that one line at a time. use std::getline(instream, str) to read a whole line at once. [/blue]
    :
    :
    :
    Well if I use getline how do I assign that string to my string variable? I can't write string str = getline(inputstream,inputfile); or I get an error. So how do I represent the contents of the string that I get from getline?
Sign In or Register to comment.