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 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
--
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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 =...
|
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...
|
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...
|
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;
| |
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
|
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:...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |