In article <40***********************@dread11.news.tele.dk> ,
JrdA <n@n.n> wrote:
Now i have a txt-file containing :
1234#01/26/04#
424#01/26/04#
324234#01/26/04#
I then need ifstream to read the first ints until it reaches the # sign and
then add them togheter.
I assume you don't need to do anything with the rest of the data on each
line.
When you read an int using >>, it will stop reading when it reaches the
first character that cannot be part of an int, so it will stop at the
first # sign. Now now you need to skip over the rest of the line, which
you can do with ignore().
ifstream input ("your.file");
int num;
while (input >> num)
{
// do whatever you need to do with num here
input.ignore (1000, '\n'); // skips past next newline, or 1000 chars,
// whichever comes first
}
Depending on the maximum posslbie line length in your file, adjust the
1000 if necessary.
--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA