473,503 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem in parsing double prec. numbers


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
Jul 29 '06 #1
3 1641
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" <to************@vp.plwrote in message
news:ea**********@news.onet.pl...
>
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


Jul 29 '06 #2


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Moonlit" <news moonlit xs4all nlwrote in message
news:44**********************@news.xs4all.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" <to************@vp.plwrote in message
news:ea**********@news.onet.pl...
>>
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



Jul 29 '06 #3
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.
Jul 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
19591
by: | last post by:
Hey I am calling Convert.ToDouble(someString); But this double can have to ways or representing doubles dependant on the locale, it can be 1.0 or 1,0 Is there a way to make...
3
12418
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
4
5237
by: Earl | last post by:
I'm curious if there are others who have a better method of accepting/parsing phone numbers. I've used a couple of different techniques that are functional but I can't really say that I'm totally...
1
3662
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList...
10
2592
by: vigacmoe | last post by:
I was trying to cast some strings to integers with stringstream, then this strange problem poped up. Here is my test code: stringstream conv; string from; int to; from = "1"; conv << from;
5
1521
by: nick048 | last post by:
Hi to All, Foollowing Your suggestion, I have written this code: #include <stdio.h> #include <string.h> #include <malloc.h> #define BUFLEN 100
4
3943
by: marathoner | last post by:
After reading the string representation of a double precision number, -0.417597000000000D+06, from a text file, I am unable to convert it to a double precision number. Here is the code I am using:...
3
11925
by: spittinfire | last post by:
-------------------------------------------------------------------------------- I am trying to correct the errors on an assignment that has already been graded because I have to now modify it and...
15
7513
by: arnuld | last post by:
Next month I will start to work on a C++ based Software named CAT++ which is going to provide FORTRAN like arrays in C++ and will be used within Scientific Community and hence will heavily depend...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.