The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Vector Traversing dhanamurthy High Level Programming 1 04-30-2008 08:20 AM
Can I use sed to insert a string which has colon Jenny.palmy UNIX for Dummies Questions & Answers 2 04-28-2008 07:04 PM
How to insert a string at the end of a file read ahjiefreak Shell Programming and Scripting 5 12-10-2007 11:38 PM
how to insert line break + string in vi (search & replace ) umen Shell Programming and Scripting 1 06-08-2006 11:42 AM
Failed to insert string into file before line nir_s Shell Programming and Scripting 7 07-26-2005 01:37 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-10-2004
photon's Avatar
photon photon is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 162
vector<string> with insert cmd

How do I correct this vector<string> insert.

I am geeting segmintation dump.


Code:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
//#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;



struct str{
  int go(vector<string> s){
    vector<string>::iterator vsitr0;
    vector<string>::iterator vsitr1;
    vector<string> vs;
    int ret = 0;
    int count = 0;
    for(vsitr0 = s.begin(); vsitr0 != s.end() - 1; ++vsitr0){
      count = 0;
      for(vsitr1 = s.end() - 1; vsitr1 != vsitr0; --vsitr1){
        if(*vsitr0 > *vsitr1){
          count++;
          // HERE IT IS/////
          s.insert(vsitr1, *vsitr0);
          ///////////////////////////////
        }
      }
      if(count > 0) ret++;
    }
    return ret;
  }
	
//////	
};

int main() {
  vector<string> s;
  s.push_back("Aaa");
  s.push_back("Ppp");
  s.push_back("C is cool");
  s.push_back("Apple");
  str m;
  int ans = 0;
  ans = m.go(s);
  cout << ans << endl;
}
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0