Start New Discussion within our Software Development Community

Hi, i want to write from one file to another. i managed to get the file to write but not in the way i expected it too, there is more to the program but for now i just need to know how can i mirror one file...
My input file contains:
peter 3 / + - *
Dahne 8 + - / *

but my outfile saves as:
...... and so on

how do i fix this? i need it to look exactly like the input file for now

#include <fstream>
#include <cstdlib>
#include <iostream>
#include <string>

int main()
    using namespace std;
    ifstream in_stream;
    ofstream out_stream;"precedence.dat");
    if( ))
        cout << "input file opening faild.\n";
    if ( ))
        cout << "output file opening failed.\n";
    //char line;
    string next;
    while(! in_stream.eof())
    out_stream<< next<< endl;
    in_stream.close( );
    out_stream.close( );
    return 0;


it ends the line after and moves the curser down to the next line. thats a good point, thank you.
now i removed the endl my out put is all in one line

peter 3 / + - *Dahne 8 + - / *

i dont know, im very new to this, i would have assumed by my text book that its reads dat files line by line and outputs it to the outfile, but it moves a line down every time it encounters a white space. ive tried using string variables but still nothing, either im getting one word per a line or one character per line.
the program itself has to have an input file that pre-filled. and a output file. from the input file it needs to extract the number and then do a switch for a calculation which ive done, then the outfile needs to save the name the /+*- symbols and the answer, my biggest hurdle is the file output, its not giving me the desired result

Ahhh, now I see the problem. I didn't look close enough.

... but it moves a line down every time it encounters a white space.

That's the definition of a read using >>. If you want to read a line you need something like getline() .

YOU ARE AWESOME!!!! thank you perfect mirror or original file

while(! in_stream.eof())
This question has already been answered. Start a new discussion instead.