Plz solve my problem

N

nik

hello friends,

i want to create a file and copy that file removing white spaces in the
file;
for ex
a file : C:\\abcd.txt
contents of file r: a b c d e.
i want to remove white spaces from the file using skipws .
how can i do this.
 
H

Howard

nik said:
hello friends,

i want to create a file and copy that file removing white spaces in the
file;
for ex
a file : C:\\abcd.txt
contents of file r: a b c d e.
i want to remove white spaces from the file using skipws .
how can i do this.

Which part are you having trouble with?

Here's an outline to get you started:

open the input file
open another output file
while (read a line of the file into a string)
remove the white space
write the string to the output file
close the files

Now, read your class notes and your textbook, and also the FAQ, esp. section
5:

http://www.parashift.com/c++-faq-lite/

-Howard
 
P

Puppet_Sock

nik said:
hello friends,

i want to create a file and copy that file removing white spaces in the
file;
for ex
a file : C:\\abcd.txt
contents of file r: a b c d e.
i want to remove white spaces from the file using skipws .
how can i do this.

Sure! Just post your instructor's email, and I will send the answer
to your assignment right over to him.
Socks
 
D

Daniel T.

"nik said:
hello friends,

i want to create a file and copy that file removing white spaces in the
file;
for ex
a file : C:\\abcd.txt
contents of file r: a b c d e.
i want to remove white spaces from the file using skipws .
how can i do this.

Here you go. Paste the below in a file, and insert code where it says
"insert code here" until you can get the program to print "GOOD JOB!".
----------------------------------------------------------------------
#include <iostream>
#include <sstream>

using namespace std;

void copy_no_whitespace( istream& is, ostream& os )
{
// insert code here
}

int main() {
stringstream iss( "a" );
stringstream result;
copy_no_whitespace( iss, result );
assert( result.str() == "a" );

iss.str( "a b" );
result.str( "" );
iss.clear();
result.clear();
copy_no_whitespace( iss, result );
assert( result.str() == "ab" );

iss.str( " a b c " );
result.str( "" );
iss.clear();
result.clear();
copy_no_whitespace( iss, result );
assert( result.str() == "abc" );

cout << "GOOD JOB!\n";
}
 
J

Jim Langston

nik said:
hello friends,

i want to create a file and copy that file removing white spaces in the
file;
for ex
a file : C:\\abcd.txt
contents of file r: a b c d e.
i want to remove white spaces from the file using skipws .
how can i do this.

One way I would probably do it is by taking advantage of istream taking
white space as a delimiter. So I would create an ifstream opening the input
file, >> to a std::string, then write the string to the output file. The
problem that you will have is when you get to the end of line '\n'. Not
sure how to know when you get there so you can get past it. Maybe someone
else can.

And the reason I didn't give you any code is because I suspect this is
homework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top