Hi!
I problems solving thins assignment:
* I want to read numbers from a file and the numbers may be seperated.like this
200ee4e 66 yyy 888
22 5 6
1
* I want to read just the numbers and sum them up.But i get problems with newline the code stops reading after newlin/space.
It reads 2 0 0 4 but jumps out before 66
Code:#include <iostream> #include <fstream> #include <cstring> using namespace std; int main(){ ifstream inputFile; char input[81]; char test[] = "0123456789"; char *ptr; int teller = 0; inputFile.open("oppgave2.txt"); if(!inputFile){ cout<<"File error\n"; } else{ inputFile>>input; ptr = strpbrk (input, test); while(ptr != NULL){ cout<<*ptr<<" "; ptr = strpbrk (ptr+1,test); } } inputFile.close(); return 0; }



LinkBack URL
About LinkBacks



