Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getline() and the evil widen('\n') call

Status
Not open for further replies.

rgallaway

Programmer
Apr 8, 2002
7
0
0
US
I have a bunch of code that I am porting from Builder 5 to Builder 6. Code that worked fine under BCB5 crashes (throws an exception, really) in the fstream fstream::getline() method. It appears that the stream is trying to access a locale facet that does not exist in the process of executing a call to fstream::widen('\n).

The file in question is a simple ASCII file that has recently been extracted from a blob field of a Paradox db using the SaveToFile() method.

I have tried explicitly setting the locale to classic C locale with no apparent effect.

What is weird that I can read the file with a TRichEdit object just fine, but getline() fails...

What ever happened to nice simple ASCII I/O anyhow? (No offense intended to the several billion people who use non-latin character sets!)
 
It has to do with how the namespace was defined in BCB5 vs. BCB6. I ran into this with all my BCB5 code and streams. Try using std::getline. Also remember with any ios calls, you also have to define the namespace, too, e.g., std::ios::app.

If you are really using locales, you have to define that namespace. I've been lucky in that I never have had to use anything but the standard namespace.

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
What ever happened to nice simple ASCII I/O anyhow? (No offense intended to the several billion people who use non-latin character sets!)
[\quote]

have we actually gone so far in our political correctness
to have to apologize for nothing anymore.

butthead
 
This problem was resolved by changing from the two parameter form of getline(char * buf, int bufsize) to the three parameter form: getline(char * buff, int bufsize, char terminator). The reason this works is that the two parameter form just calls the three parameter form like this: getline(buf,bufsize,widen('\n')). It was the widen('\n') that was causing the problem anyhow, so I just worked around it.

The downside is that this change involved something like 160 code changes... lots of room for boo boos!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top