help with appending input to output file

Hi, Im trying to write a code from an input file that has advice about programing, then adds the exisiting content and the new content to an output file. I believe my function calls, using get, are incorrect but not sure how to correct them or which one I should use. Any help would be greatly appreciated.

heres where I am:

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;



int main(){

using namespace std;
ifstream in_stream;
ofstream out_stream;

in_stream.open("C:\\Documents and Settings\\Administrator\\Desktop\\HW\\HW4\\hw4pr5input.txt");


if (in_stream.fail())
{
cout << "Input file opening failed.\n";
system ("pause");
exit(1);
}

out_stream.open("hw4pr5input_output", ios::app);

if (out_stream.fail())
{
cout << "Output file opening failed.\n";
system ("pause");
exit(1);
}

while(out_stream)
{cout<<in_stream<<endl;
get(out_stream,in_stream);
}
out_stream.close();
out_stream.clear();
out_stream.open("hw4pr5input_output.txt", ios::out | ios::app);
if(out_stream.fail())
{ cout<<"file opening failed\n";
system("pause");
return 0;
}
cout<< "give any advice and press enter twice when completed\n";


get(cin,in_stream);
while(in_stream.length()>0)
{
out_stream<<in_stream<< endl;
get(cin, in_stream);
}
out_stream.close();
system("pause");
return 0;

}
Please edit your code using code tags.

Aceix.
what is code tags?
When you add or edit a reply, wrap any code inside [code.][/code.] (without the .), or alternatively select / highlight all the code and hit the button <> next to B, I, U, etc..
Last edited on
click the edit button below your your post, then on the right side of the edit box, under Format, click
<>
, then insert your code beetween the "code tags" ->
[code] [/code]
Last edited on
Anyway, you can use the get member function this way: in_stream.get(out_stream);

Sorry for the late post...was at church
Aceix.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>
#include <string>

int main()
{
    // open ouptput file; truncate it if it exists, create it if it doesn't
    std::ofstream output( "output.txt" ) ;

    // copy the contents of input file to output
    if( output << std::ifstream( "input.txt" ).rdbuf() )
    {
        // if successfull, append lines entered by the user to output
        std::cout << "enter additional lines to be appended (eof when done)\n" ;
        std::string line ;
        while( std::getline( std::cin, line ) ) output << line << '\n' ;
    }

    else std::cerr << "failed to copy input file to output\n" ;
}
Topic archived. No new replies allowed.