Re: [OT] C++ programming: keeping count of data items read from file



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@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: Painful upgrade from XFree86 to X.Org
    ... session. ... HTH ... Jim ... To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org ...
    (Debian-User)
  • Re: UDF producing #NAME?
    ... > Hi Jim, ... > Function ColumnLetterAs String ... > HTH ... >>> Hank Scorpio ...
    (microsoft.public.excel.misc)
  • Re: Number sequence
    ... ByVal fld As String) As String ... use two or three digits. ... '{increments a digit in a sequence field. ...
    (microsoft.public.access.forms)
  • Re: Integer to string conversion
    ... I think Jim probably has the best solution but we haven't covered ... templates yet and they seem very confusing, ... I'm trying to convert an integer into a string. ... char buf; ...
    (comp.lang.c)
  • Re: Speed this up for me, please
    ... Many thanks Jim. ... Function Sinfo_R1(ByRef lookupKey As String, ByRef lookupVal As String, _ ... Dim rng As Excel.Range ... The first row of the sheet contains titles for the columns. ...
    (microsoft.public.excel.programming)