Re: point type of array....... confused

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 09/07/04


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



Relevant Pages

  • Re: Still have open references even after using CComPtr<>
    ... in the ppf parameter, as the pSink parameter in the ... Trim & respond inline (please don't top post or snip everything) ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: remove consecutive blank lines
    ... the trailing white space in the current record (e.g. the sequences of tabs ... also will compress sequences of white space within the text which may be ... a gawk extension. ...
    (comp.lang.awk)
  • Re: Getting nanoseconds in a process
    ... Golden California Girls writes: ... negatives cancel each other out (like two "!" ... -j Doesn't the white space make the first - a subtraction operator? ...
    (comp.lang.c)
  • Re: Still have open references even after using CComPtr<>
    ... My signature below says "2. ... Trim & respond inline (please don't top post or snip everything) ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: parse two field file
    ... two fields seperated by a tab. ... (The first "%s" will skip any leading white space, ... Plus unbounded %or %s risks buffer overflow and resulting UB. ... to find the first tab <snip> ...
    (comp.lang.c)