0

I have to read integers from file, that are written for example so: The first number shows the number of the lines.

4
2 44
11 3
44 3
2 11

This should be the result: [2:44][11:3][44:3][2:11]

This is my code:

int read() {
    std::ifstream file("file.dat");
    int s;
    int p;

    if (!file) {
        std::cout<<"File cant´t be open"<<std::endl;
        return 0;
    }else {
    while(file>>s && file>>p) {

        std::cout<<"["<<s<<":"<<p<<"]";
    }
    /*  for(int i=0; i<count; i++) { 
            std::cout<<"["s[i]<<":"<<p[i]<<"]";
*/

file.close(); 
}
return 0;

}

But the result is: [4:2][44:11][3:44][3:2]

How can I define,that the first number shows the lines,where the two numbers stay?

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182

0 Answers0