White Space problems

Hi everybody,
Just wondering how to remove white space from a string. I have to take input file and use comma as a delimiter to create a new line, well the white space after comma has got to go and not go into the new output file. Here is code and input .txt. I'll be working on it in the meantime.

INPUT
one, two, three, four, five,
six, seven, eight, nine, ten,
1,2,3,4,5,6,7,8,9,10

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

using namespace std;


const string INPUT_FILE = "tokens.txt";

// File containing tokens split on a comma.
const string OUTPUT_COMMA_FILE = "comma.txt";


// Connects the input file handle to the filename. Returns the status
// of the connection (true or false).
bool Connect2Input(string Filename, ifstream& fin);

// Connects the output file handle to the filename. Returns the status
// of the connection (true or false).
bool Connect2Output(string Filename, ofstream& fout);

// Reads from the input file and writes to the output file each token,
// delimeted by the specified delimeter. Read the file one character at
// a time and if the character read matches the delimeter, then write a
// newline else if the read character does not match the delimeter,
// write the character. Do not write any white spaces to the output file.
void Split(ifstream& fin, ofstream& fout, char input);



int main()
{ char input;
ifstream fin;
ofstream fout;

if ( Connect2Input(INPUT_FILE, fin) == false)
{
cerr << "Error opening file " << INPUT_FILE << " for reading. Aborting!"
<< endl;
exit(1);
}

if ( Connect2Output(OUTPUT_COMMA_FILE, fout) == false)
{
cerr << "Error opening file " << OUTPUT_COMMA_FILE << " for reading. Aborting!"
<< endl;
exit(1);
}
fin>>input;
Split(fin, fout, input);
fin.close();
fout.close();

} // end main()

bool Connect2Input (string Filename, ifstream& fin)
{
bool success = true;
fin.open( Filename.c_str() );
if ( fin.fail() )
{
success = false;
}

return (success);
}

bool Connect2Output(string Filename, ofstream& fout)
{
bool success = true;
fout.open( Filename.c_str() );
if ( fout.fail() )
{
success = false;
}

return (success);
}
// Reads from the input file and writes to the output file each token,
// delimeted by the specified delimeter. Read the file one character at
// a time and if the character read matches the delimeter, then write a
// newline else if the read character does not match the delimeter,
// write the character. Do not write any white spaces to the output file.
void Split(ifstream& fin, ofstream& fout, char input)

{

while (!fin.eof())

{
if (input == ',')
{
fout<<endl;
}
else
{
fout<<input;
}
fin.get(input);
}
}
Alright so I added another else if to say when it sees a ' ' to make it a "". but the return after a line in the input is causing my output to have an extra space after five and ten

five

six...
ten

1

hmmmmmm
Topic archived. No new replies allowed.