Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > problem in parsing double prec. numbers

Reply
Thread Tools

problem in parsing double prec. numbers

 
 
Tomasz Bednarz
Guest
Posts: n/a
 
      07-29-2006

Can someone help me to parse double precision numbers from text file?

I have a sample text file which is as follows:

VARIABLES = x, y
ZONE I=11, J=11
1.10000000000 0.10000000000
0.10000000000 0.20000000000
0.20000000000 0.30000000000
0.30000000000 0.40000000000
0.40000000000 0.50000000000
....
....

The problem is in reading x and y...
I did such function:

istringstream stm;
string lline;
ifstream fp (filename);
if ( fp.is_open() )
{
for (i...
for (j...
{
getline(fp,lline);
stm.str(lline);
stm >> x(i,j) >> y(i,j);
}
....
....

It works only on some files (when using g++) don't know why and doesn't
work at all when using compiler from visual c++ 2005!
Am getting nothing in x(i,j) and y(i,j) (zeros)...

Please give me some suggestions if you could,

kind regards,
Tomasz


 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      07-29-2006
Hi,

Don't know if this is the problem but for one thing files on windows are
opened as text files while on unix'es there is no difference so it is better
to open the files as binary (so the result is the same in vs as it is in
g++)

ifstream Input( Filename.c_tr(), ios_base::binary);

Another thing is I think it is better to account for more numbers on a line

while( strm >> number1 >> number2 )
{
....
}

--


Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Tomasz Bednarz" <(E-Mail Removed)> wrote in message
news:eafb4i$dgh$(E-Mail Removed)...
>
> Can someone help me to parse double precision numbers from text file?
>
> I have a sample text file which is as follows:
>
> VARIABLES = x, y
> ZONE I=11, J=11
> 1.10000000000 0.10000000000
> 0.10000000000 0.20000000000
> 0.20000000000 0.30000000000
> 0.30000000000 0.40000000000
> 0.40000000000 0.50000000000
> ...
> ...
>
> The problem is in reading x and y...
> I did such function:
>
> istringstream stm;
> string lline;
> ifstream fp (filename);
> if ( fp.is_open() )
> {
> for (i...
> for (j...
> {
> getline(fp,lline);
> stm.str(lline);
> stm >> x(i,j) >> y(i,j);
> }
> ...
> ...
>
> It works only on some files (when using g++) don't know why and
> doesn't work at all when using compiler from visual c++ 2005!
> Am getting nothing in x(i,j) and y(i,j) (zeros)...
>
> Please give me some suggestions if you could,
>
> kind regards,
> Tomasz
>
>



 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      07-29-2006


--


Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Moonlit" <news moonlit xs4all nl> wrote in message
news:44cb48d3$0$4531$(E-Mail Removed)4all.nl...
> Hi,
>
> Don't know if this is the problem but for one thing files on windows are
> opened as text files while on unix'es there is no difference so it is
> better to open the files as binary (so the result is the same in vs as it
> is in g++)
>
> ifstream Input( Filename.c_tr(), ios_base::binary);

Sorry that should be Filename.c_str() obviously
>
> Another thing is I think it is better to account for more numbers on a
> line
>
> while( strm >> number1 >> number2 )
> {
> ...
> }
>
> --
>
>
> Regards, Ron AF Greve
>
> http://moonlit.xs4all.nl
>
> "Tomasz Bednarz" <(E-Mail Removed)> wrote in message
> news:eafb4i$dgh$(E-Mail Removed)...
>>
>> Can someone help me to parse double precision numbers from text file?
>>
>> I have a sample text file which is as follows:
>>
>> VARIABLES = x, y
>> ZONE I=11, J=11
>> 1.10000000000 0.10000000000
>> 0.10000000000 0.20000000000
>> 0.20000000000 0.30000000000
>> 0.30000000000 0.40000000000
>> 0.40000000000 0.50000000000
>> ...
>> ...
>>
>> The problem is in reading x and y...
>> I did such function:
>>
>> istringstream stm;
>> string lline;
>> ifstream fp (filename);
>> if ( fp.is_open() )
>> {
>> for (i...
>> for (j...
>> {
>> getline(fp,lline);
>> stm.str(lline);
>> stm >> x(i,j) >> y(i,j);
>> }
>> ...
>> ...
>>
>> It works only on some files (when using g++) don't know why and
>> doesn't work at all when using compiler from visual c++ 2005!
>> Am getting nothing in x(i,j) and y(i,j) (zeros)...
>>
>> Please give me some suggestions if you could,
>>
>> kind regards,
>> Tomasz
>>
>>

>
>



 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      07-29-2006
Tomasz Bednarz wrote:

> It works only on some files (when using g++) don't know why and doesn't
> work at all when using compiler from visual c++ 2005!
> Am getting nothing in x(i,j) and y(i,j) (zeros)...
>
> Please give me some suggestions if you could,
>

You might try explicitly clearing the flags on the stream (or
just move the definition inside the for loops so that you get
a new one each time.

The standard doesn't explicitly say that str() clears the
flag when "initializing the sequences". If you get an error
(as you will on the first two lines that don't have numeric
values) it will never succeed later.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding 1000 largest numbers from a file having some billion numbers Subra C Programming 25 03-08-2007 01:31 AM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
Frame Numbers vs. JPEG Numbers With CF Cards mort Digital Photography 3 02-16-2005 01:43 AM
Double double display display problem problem Tom Accuosti Firefox 3 09-27-2004 10:02 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments