Thank you for your reply.
So now, why the following code, i don't understand why the vector size is 25, if there are 55 number to input...
The code compiles and run well, the problem is that should be 55 number inside the vector.
Please help
PHP Code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<int> Leer ()
{
vector<int> elementos;
ifstream archivo("moving.in");
if (archivo.is_open())
{
char dato_string[8];
while ( archivo.getline( dato_string , sizeof dato_string ) )
{
char *dato_char = strtok( dato_string," " );
while ( dato_char != NULL )
{
int dato_numero = atoi( dato_char );
elementos.push_back( dato_numero );
dato_char = strtok( NULL, " " );
}
}
archivo.close();
}
else
{
cout << "No se puede abrir el archivo";
}
return elementos;
}
int main ()
{
vector<int> resultados = Leer();
// output resultados
for ( unsigned int i = 0; i < resultados.size(); ++i )
{
cout << resultados[i] << endl;
}
return 0;
}
using this input "moving.in":
Code:
15
2
3 4
5 70
3
34 56
21 89
32 90
2
34 45
32 56
5
56 78
12 34
45 74
123 345
13 400
4
9 12
3 5
4 78
45 46
2
3 4
5 70
3
34 56
21 89
32 90
2
34 45
32 56
5
56 78
12 34
45 74
123 345
13 400
4
9 12
3 5
4 78
45 46
2
3 4
5 70
3
34 56
21 89
32 90
2
34 45
32 56
5
56 78
12 34
45 74
123 345
13 400
4
9 12
3 5
4 78
45 99