I get the right input, but its giving out the numbers unformatted in the output ie: when it should be
input:
3 5 (7)
$58 3,400

output:
3 5 -7
58 3400

it gives me
3
5
-7

5
8


3
4
0
0

inFile.get(aa);
while( ! inFile.eof())
{
	switch(aa)
	{
		case '$':
			break;
		case ',':
			break;
		case '(':
			outFile << '-';
			break;
		case ')':
			break;
		case '\t':
			break;
		default:
			outFile << aa << endl;
			break;
	}
	inFile.get(aa);

}

inFile.close();
outFile.close();
Ancient Dragon commented: using code tags correctly the first time :) +36

Recommended Answers

All 5 Replies

Look at the statement:

outFile << aa << endl;

<<endl prints newline and flushes output buffer. That's why your program prints every char on the new line...

Yeah I feel silly. LOL thanks.

Member Avatar for iamthwee

Avoid using eof to control file i/o:

Avoid using eof to control file i/o:

why is that?

well... i'm not that good with c++ I/O (c ftw), but if you're using fstream, you can make two streams and use them for I/O, for example if the input stream is called 'input' you can go with

while( input >> aa ) {/*blahblah...*/}

...well i guess you can... hmm, i'm all sleepy, maybe i just made it all up
//edit: btw i think it's lookin for eof this way too, cause input is true while there's something to input, but when the file's empty...oops.. return 0; kkthxbai

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.