-
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
-
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
-
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
-