How can I copy a text file into another?

Aviv Cohn

How can I copy a text file into another? I tried this:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream infile("input.txt");
    ofstream outfile("output.txt");
    outfile << infile;

    return 0;
}

This just ends up leaving the following value in output.txt: 0x28fe78.

What am I doing wrong?

Smith

You can save the content of the infile in a string and put it out into the other file. Try this:

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

using namespace std;

int main ()
{
    ifstream infile("input.txt");
    ofstream outfile("output.txt");
    string content = "";
    int i;

    for(i=0 ; infile.eof()!=true ; i++) // get content of infile
        content += infile.get();

    i--;
    content.erase(content.end()-1);     // erase last character

    cout << i << " characters read...\n";
    infile.close();

    outfile << content;                 // output
    outfile.close();
    return 0;
}

Best regards Paul

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I read a text file from the terminal and save the output to another file in java?

분류에서Dev

How to copy contents of one text file to another with reduced length?

분류에서Dev

How can I copy one vector to another through different classes

분류에서Dev

Copy a block of text to a specific point in another file

분류에서Dev

How can I call a batch file within another batch file?

분류에서Dev

How do I copy a file from one server to another without downloading first?

분류에서Dev

How can I get a part of text file by terminal

분류에서Dev

how can I read from an uploaded text file

분류에서Dev

How can I run a specific line as a command in a text file?

분류에서Dev

How can I remove text on the last line of a file?

분류에서Dev

How can I extract text before a character or string in a batch file?

분류에서Dev

How can I copy HTML textbox values from one domain to another domain's textboxes?

분류에서Dev

How can I copy locations from one campaign to another in Google Adwords?

분류에서Dev

How can I display text from a file automatically after powering up my computer, in text editor or terminal?

분류에서Dev

How do I can change contents of some div sections while clicking text from another div

분류에서Dev

Can I recover this corrupted text file

분류에서Dev

While in vi how can I pull in / insert / paste the contents of another file

분류에서Dev

How can I post data to another file and render from it using DomPDF

분류에서Dev

How can i get from the List<string> of files each time another file?

분류에서Dev

Can I copy large files faster without using the file cache?

분류에서Dev

How do i copy files from one directory to another directory?

분류에서Dev

How can I delete a fixed part of some lines from a text file?

분류에서Dev

How can I append an incremental count to every predefined word of a text file?

분류에서Dev

How can I use another drive with Owncloud?

분류에서Dev

How can I refer a launchpad ppa in another?

분류에서Dev

How to copy specific text?

분류에서Dev

How can I move text to the left with CSS?

분류에서Dev

How can I automate inputting text into a prompt?

분류에서Dev

How can I copy&paste from the host to a KVM guest?

Related 관련 기사

  1. 1

    How can I read a text file from the terminal and save the output to another file in java?

  2. 2

    How to copy contents of one text file to another with reduced length?

  3. 3

    How can I copy one vector to another through different classes

  4. 4

    Copy a block of text to a specific point in another file

  5. 5

    How can I call a batch file within another batch file?

  6. 6

    How do I copy a file from one server to another without downloading first?

  7. 7

    How can I get a part of text file by terminal

  8. 8

    how can I read from an uploaded text file

  9. 9

    How can I run a specific line as a command in a text file?

  10. 10

    How can I remove text on the last line of a file?

  11. 11

    How can I extract text before a character or string in a batch file?

  12. 12

    How can I copy HTML textbox values from one domain to another domain's textboxes?

  13. 13

    How can I copy locations from one campaign to another in Google Adwords?

  14. 14

    How can I display text from a file automatically after powering up my computer, in text editor or terminal?

  15. 15

    How do I can change contents of some div sections while clicking text from another div

  16. 16

    Can I recover this corrupted text file

  17. 17

    While in vi how can I pull in / insert / paste the contents of another file

  18. 18

    How can I post data to another file and render from it using DomPDF

  19. 19

    How can i get from the List<string> of files each time another file?

  20. 20

    Can I copy large files faster without using the file cache?

  21. 21

    How do i copy files from one directory to another directory?

  22. 22

    How can I delete a fixed part of some lines from a text file?

  23. 23

    How can I append an incremental count to every predefined word of a text file?

  24. 24

    How can I use another drive with Owncloud?

  25. 25

    How can I refer a launchpad ppa in another?

  26. 26

    How to copy specific text?

  27. 27

    How can I move text to the left with CSS?

  28. 28

    How can I automate inputting text into a prompt?

  29. 29

    How can I copy&paste from the host to a KVM guest?

뜨겁다태그

보관