From: Jordi Gutiérrez Hermoso on
On 06/05/2008, H.S. <hs.samix(a)gmail.com> wrote:
> If you have visited that, it is full of people who want to discuss only the
> standard.

The standard is nice. The standard is great. I love the standard. It
can do everything, and when it can't, then you use Boost who does the
rest.

Wrapping other languages with C++ can be messy, but even standard C++
helps with that. Now, other languages aren't C++, are they?

My answers regarding C++ are almost always going to be to use the
standard library objects and functions and to use them generously,
unless you have an *irrefutable* reason for why you should use
homebrewed subpar methods instead of standard C++. If you're going to
be reading doubles one by one, and you want to store those doubles and
know how many you have, I see little reason to not use an std::list
unless you explain further why you need to keep the data in the ARPACK
format.

Fwiw, there's very little C++ code out there that's really standard
and beautiful. I can think of Battle for Wesnoth as some of the nicest
C++ code out there (and it uses Boost).

On 06/05/2008, H.S. <hs.samix(a)gmail.com> wrote:
> Yup, that fscanf method looks interesting. I used that only when I program
> in C, but it might be judicious to use it in C++ in this situation.

It's not. Streams are better and keep you away from nasty errors and segfaults.

Use getline(istream, string).

Suppose ifs is some istream (e.g ifstream ifs("file.data");).

Then you do something like

string s;
while(getline(ifs,s)){
stringstream ss;
ss << s;
double x;
list this_line;
while(ss >> x){
// Read the doubles one by one into some data structure
this_line.push_back(x);
}
if(this_line.size() != rows){
//Handle error here somehow
}
}

If you need more fine control than this, you use boost::tokenizer.

HTH,
- Jordi G. H.


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
From: Mark Allums on
James Allsopp wrote:
> hi,
> Try something like this, just add some pointers;
> scan is just a simple object and l is a class vector.
> HTH
> jim
>
> int nearest::readdata(std::string s, std::vector<scan> & l)
> {
> //read in scuba core list
> std::ifstream input(s.c_str());
> std::string temp, pos, x ,y;
> char * t;
> std::cout <<"Reading " << s <<std::endl;
> while(!getline(input,temp).eof())
> {
> scan n;
> std::stringstream s(temp);
> s >> n.name;
> s >> x;
> s >> y;
> n.glon=strtod(x.c_str(),&t);
> n.glat=strtod(y.c_str(),&t);
> l.push_back(n);
> }
> input.close();
> return 0;
> }
>

This is something like I meant when I said do it the C++ way, or the C
way. Except that I gave a bad example of the C way, this is a better
example, which is of a C++ way. It would help if I knew the C++
iostream stuff better. If this weren't so darned OT, I'd ask what a
"scan" is.

(And is also an example of something that is wrong with the C++ standard
library, when you need the c_str() member of string so often to get any
real useful work done. Kind of defeats the purpose of having string in
the first place.)

The totally unhelpful, but trying to be encouraging,

Mark Allums


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
From: Ron Johnson on
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/06/08 13:25, H.S. wrote:
> Ron Johnson wrote:
>>
>> Is this a binary file or a text file?
>
> hmm. Text. I made it clear in the original post.

Sorry. It just seems (to an old C programmer) that this is pretty
simple problem, unless there's some tricky detail that you aren't
telling us.

- --
Ron Johnson, Jr.
Jefferson LA USA

We want... a Shrubbery!!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIIMcsS9HxQb37XmcRAhs6AKDDQ8KXvkspc5xLZoj9l29TrnvV6gCcCUO0
ZggE4aBh+kOQ0/gP712BRVM=
=A44m
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
From: H.S. on
Jordi Guti�rrez Hermoso wrote:
> On 06/05/2008, H.S. <hs.samix(a)gmail.com> wrote:
> homebrewed subpar methods instead of standard C++. If you're going to
> be reading doubles one by one, and you want to store those doubles and
> know how many you have, I see little reason to not use an std::list

From the snippet of code you gave below, it doesn't look necessary to
know how many doubles I want to read before grabbing the whole line in
to a list. In fact, looks like the line will straight away give me how
many double are there in a line and I can compare this number with the
one I expect ... providing me with a sanity check.

> unless you explain further why you need to keep the data in the ARPACK
> format.

APRACK FORTRAN library needs the input data in a 2D array (the arrays
need to be arranged in column-major format). But, to answer your query,
I don't *have* to read it in an array, I could read it in a list and
then copy it to an array before I call ARPACK routines.


> Fwiw, there's very little C++ code out there that's really standard
> and beautiful. I can think of Battle for Wesnoth as some of the nicest
> C++ code out there (and it uses Boost).

I try to keep is according the C++ standard as far as I can. For all my
programs, I use the "-ansi" flag with g++.


> On 06/05/2008, H.S. <hs.samix(a)gmail.com> wrote:
>> Yup, that fscanf method looks interesting. I used that only when I program
>> in C, but it might be judicious to use it in C++ in this situation.
>
> It's not. Streams are better and keep you away from nasty errors and segfaults.

Totally agree about the streams point.


> Use getline(istream, string).

Yes, this is what I was just now reading about.


> Suppose ifs is some istream (e.g ifstream ifs("file.data");).

The following seems to be quite nice, and "C++ way" to do it. I am going
to try that now. Thanks a ton.

->HS


> Then you do something like
>
> string s;
> while(getline(ifs,s)){
> stringstream ss;
> ss << s;
> double x;
> list this_line;
> while(ss >> x){
> // Read the doubles one by one into some data structure
> this_line.push_back(x);
> }
> if(this_line.size() != rows){
> //Handle error here somehow
> }
> }
>
> If you need more fine control than this, you use boost::tokenizer.
>
> HTH,
> - Jordi G. H.
>
>


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
From: H.S. on
Mark Allums wrote:

> (And is also an example of something that is wrong with the C++ standard
> library, when you need the c_str() member of string so often to get any
> real useful work done. Kind of defeats the purpose of having string in
> the first place.)

Yes, that c_str() is a nuisance many times. I remember a few years back
when older C++ code refused to compile with a newer gcc version (there
are a major version change in gcc back then) and I had to manually put
that .c_str() at many places in a source that I was using.


> The totally unhelpful, but trying to be encouraging,
>
> Mark Allums
>
>


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org