LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [C++] What does this mean? (https://www.linuxquestions.org/questions/programming-9/%5Bc-%5D-what-does-this-mean-639469/)

thursgun 05-02-2008 05:59 PM

[C++] What does this mean?
 
Befor posting any code, I would like to know what does this means:

Code:

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check
Aborted

Thank you.

Smedley 05-02-2008 06:04 PM

Read this:

http://www2.roguewave.com/support/do...ef/vector.html

and this:

http://gpwiki.org/index.php/C_plus_p...s_plus:Vectors

thursgun 05-02-2008 06:54 PM

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<intLeer () 
{
  
vector<intelementos

  
ifstream archivo("moving.in");

  if (
archivo.is_open())
  {
    
char   dato_string[8];

    while ( 
archivo.getlinedato_string sizeof dato_string ) )
    {
      
char *dato_char strtokdato_string," " );

      while ( 
dato_char != NULL )
      {
        
int dato_numero atoidato_char );

        
elementos.push_backdato_numero );

        
dato_char strtokNULL" " );
      }
    }

    
archivo.close();
  }
  else 
  {
    
cout << "No se puede abrir el archivo";
  }

  return 
elementos;
}


int main ()
{
  
vector<intresultados Leer();

  
// output resultados
  
for ( unsigned int i 0resultados.size(); ++)
  {
    
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


ntubski 05-04-2008 03:51 PM

Quote:

Originally Posted by thursgun (Post 3140501)
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.

How are you counting the numbers? There are 112 numbers, and the code did output 112 lines when I ran it.


All times are GMT -5. The time now is 08:07 PM.