LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2008, 05:59 PM   #1
thursgun
LQ Newbie
 
Registered: Jul 2007
Posts: 10

Rep: Reputation: 0
[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.
 
Old 05-02-2008, 06:04 PM   #2
Smedley
Registered User
 
Registered: Apr 2008
Distribution: Slackware
Posts: 74

Rep: Reputation: 15
Read this:

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

and this:

http://gpwiki.org/index.php/C_plus_p...s_plus:Vectors
 
Old 05-02-2008, 06:54 PM   #3
thursgun
LQ Newbie
 
Registered: Jul 2007
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 05-04-2008, 03:51 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by thursgun View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration