473,698 Members | 2,747 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,llin e);
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 1661
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::binar y);

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,llin e);
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::binar y);
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.1000000000 0 0.10000000000
0.1000000000 0 0.20000000000
0.2000000000 0 0.30000000000
0.3000000000 0 0.40000000000
0.4000000000 0 0.50000000000
...
...

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

istringstrea m stm;
string lline;
ifstream fp (filename);
if ( fp.is_open() )
{
for (i...
for (j...
{
getline(fp,lli ne);
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 "initializi ng 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
19638
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 Convert.ToDouble(..) accept both comma and period notations for representing numbers?
3
12430
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 = 1000000000.99994; Debug.WriteLine(string.Format("a={0:F10}", da));
4
5264
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 happy with either. 1. My first technique was to restrict the users to entries that could only be 3 character, 3 characters, 4 character (area code, prefix, suffix, respectively). I would null out any inputs that were non-numeric (except the...
1
3699
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 records = root.ChildNodes;
10
2618
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
1527
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
3956
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: string result = block.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); double temp1 = double.Parse(result); After the last statement, I get an unhandled exception.
3
11938
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 add to it for my next assignment. I dont want to go to my next assignment when I cannot even fix this error. The error and it is the only error I have thank goodness, says "reached end of file while parsing". Can anyone please take a look, thank you...
15
7532
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 on Numerical-Computations. I was reading 29.16 ans 29.17 sections of FAQs: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.16 as a test, I just tried this program on Linux, GCC 4.2.2 and it gave me 2 different results:
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.