copying files

This is a discussion on copying files within the C++ Programming forums, part of the General Programming Boards category; im having trouble learning the whole data file stuff... what i want to do is copy a text file.. lets ...

  1. #1
    Unregistered
    Guest

    copying files

    im having trouble learning the whole data file stuff... what i want to do is copy a text file.. lets say the name be "stuff.txt" . and im tryin to figure out a way to copy that file and removes any blank spaces in the file. im tryin to go about this in simple commands.. so that i actaully learn it.. like ifstream infile; kind of stuff.
    i would really appreciate anyones help! thx

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    for the problem of copying file you could do something like this

    ----
    ifstream infile;
    ofstream outfile;

    infile.open("stuff.txt");
    outfile.open("stuff2.txt');

    while(!infile.eof())
    {
    infile>>data;
    outfile<<data;
    }

    infile.close();
    outfile.close();
    ----

    as for removing the spaces you could do this in the while loop

    if(data!=' ')
    outfile<<data;


    hope this helps

  3. #3
    Unregistered
    Guest
    using << and >> will remove whitespaces because they are not included as part of the input. If you have multiple data types in the file, this method will not work.

    you could input one character at a time from the file and then output that character to the new file if it isn't a whitespace.
    remember that \n is also a whitespace character

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    use infile.get(data)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using mmap for copying large files
    By rohan_ak1 in forum C Programming
    Replies: 6
    Last Post: 05-13-2008, 08:12 AM
  2. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  3. Copying Files
    By HLA91 in forum C++ Programming
    Replies: 8
    Last Post: 10-25-2007, 03:24 AM
  4. Help with loading files into rich text box
    By blueparukia in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 12:59 AM
  5. Copying binary files, like ZIPs
    By frenchfry164 in forum C++ Programming
    Replies: 4
    Last Post: 03-16-2002, 02:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21