Link to home
Start Free TrialLog in
Avatar of anAppBuilder
anAppBuilderFlag for United States of America

asked on

How do I get a string from a file using ifstream

I want to read a char array from a file using ifstream.  However I am getting extra garbage at the end of the read in string.  How do I eliminate that?   Please see attached files.

Thank you!
myTest.cpp
testFile.txt
stringAsReadIn.txt
Avatar of ozo
ozo
Flag of United States of America image

cString[length]='\0';
cout <<  "==>" << cString << "<==" << endl;
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anAppBuilder

ASKER

Thank you, Sara.  Very clear explanation.  I've gotten many  accurate and helpful answers from Expert's Exchange.  This is one of the best:  clear, accurate and very well-written.