Re: point type of array....... confused
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 09/07/04
- Next message: Chris \( Val \): "Re: Pointers to functions"
- Previous message: Francis Glassborow: "Re: Pointers to functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 8 Sep 2004 02:24:16 +1000
"Karl Heinz Buchegger" <kbuchegg@gascad.at> wrote in message
news:4132EB2D.6E0E91DD@gascad.at...
| Air wrote:
| >
| > I have a file called point.txt which contains some point data something like
| > 0.0,0.0
| > 1.0,0.0
| > 2.0,0.0
| > 0.0,1.0
| > 0.0,2.0 ..........etc
[snip]
Hi Karl.
| why not simply?
|
| double x, y;
| char delimiter;
|
| while( infile >> x >> delimiter >> y ) {
| // do something with the read values of x and y
| }
I just noticed that, the above read will fail, because
there is no white space between the comma separated
values, and the extraction operator will cause the
stream to break.
| Granted. This is a bit of a problem for error checking.
| Reading a whole line is often simpler (but don't use
| character arrays, use the classes C++ already offers
| to you)
[snip]
True, but I still don't know if stringstreams are
as good as plain 'ol' std::getline for this code at
least.
| std::string InLine;
|
| while( getline( inFile, InLine ) ) {
| // Here a complete line is read, do something with it
| // eg, put it into pieces
|
| std::istringstream Line( InLine );
| double x, y
| char delimiter;
|
| if( ! Line >> x >> delimiter >> y ) {
| std::cout << "There was an error in line '"<< InLine << "'\n";
[snip]
The above still suffers from the same problem to do
with the comma delimiter and no available white space.
Maybe something like the following is more suitable ?:
inline std::istream& operator >> ( std::istream& Stream, Point& rhs )
{
std::string Buffer;
while( std::getline( Stream, Buffer, ',' ) )
return Stream;
}
Over and out :-)
Chris Val
- Next message: Chris \( Val \): "Re: Pointers to functions"
- Previous message: Francis Glassborow: "Re: Pointers to functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|