Sponsored Content
Top Forums Programming vector<string> with insert cmd Post 55393 by photon on Friday 10th of September 2004 03:44:39 PM
Old 09-10-2004
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;
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

fetch string and insert later

"are you billy_smith ?" replace with "are you billy_smith ? my name is billy_smith" how to fetch the name "billy_smith" and using it later I need sed script to do this, any one can help? Thanks (6 Replies)
Discussion started by: playinmel.com
6 Replies

2. UNIX for Dummies Questions & Answers

cmd sequence to find & cut out a specific string

A developer of mine has this requirement - I couldn't tell her quickly how to do it with UNIX commands or a quick script so she's writing a quick program to do it - but that got my curiousity up and thought I'd ask here for advice. In a text file, there are some records (about half of them)... (4 Replies)
Discussion started by: LisaS
4 Replies

3. Programming

Shared Memory and String,Vector

How can i user string or vector ins shared memory ? For example i have a structure sharedInfo like below struct sharedInfo { string szName; int iAge; string szAddrees; }; if i use this notation my program crashes. And if i use char szName, it work fine, what is wrong with... (4 Replies)
Discussion started by: helpmeforlinux
4 Replies

4. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

5. Programming

I need to scan my 'vector<string> mystrings' for duplicate entries.

Basically I'm trying to avoid writing paragraphs to do it. It is possible I could convert over to a vector<int>'s if that may help. Does anyone know how to do this without really turning it into a huge brainbuster? I have considered using a for() loop but I wasn't able to put anything into practice... (1 Reply)
Discussion started by: sepoto
1 Replies

6. Shell Programming and Scripting

Insert string in alternate lines

Hi All, In continuation of my previous thread 'Add text at the end of line conditionally', I need to further modfiy the file after adding text at the end of the line. Now, I need to add a fixed charater string at alternate lines starting from first line using awk or sed.My file is now as below:... (10 Replies)
Discussion started by: angshuman
10 Replies

7. Shell Programming and Scripting

How to paste string yanked into an edit in cmd mode?

I have 2 files open in Vim at the same time. I yank from one with 16yw and get this INSERT INTO ALIS_PART_MANU_PART_TAB (SEQUENCE_NO,PART_NO,MANU_NO,MANU_PART_NO,ROWVERSION) VALUES ( Now I go to the second file and type the command to add this to the beginning of every... (3 Replies)
Discussion started by: djehresmann
3 Replies

8. Shell Programming and Scripting

Need to insert a comment string

I need to insert a comment string to a couple of fields for every line in the file. Different comment string for each field. In below file, fields 7 and 8 "R","1","t0000684","","10/31/2013","10/31/2013","","","","750.23"... (6 Replies)
Discussion started by: Melah Gindi
6 Replies

9. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

10. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies
Statistics::Basic::_OneVectorBase(3pm)			User Contributed Perl Documentation		    Statistics::Basic::_OneVectorBase(3pm)

NAME
Statistics::Basic::_OneVectorBase - base class objects like Mean METHODS
query() Query the value of the object. It will return the undefined value until there's something to calculate (or until the vector is full when nofill is in effect). insert() Insert new values into the vector. $object_instance->insert( 4, 3 ); # insert a 3 and a 4 This function returns the object itself, for chaining purposes. append() ginsert() The growing insert inserts new elements, growing the max size of the vector to accommodate the new elements (if necessary). $object_instance->ginsert( 4, 3 ); # append a 3 and a 4 This function returns the object itself, for chaining purposes. query_size() The current size of the vector -- regardless of its max size (as set by "set_size()"). query_vector() Returns the Statistics::Basic::Vector object used by the computational object. set_size() Set the maximum size for the underlying Statistics::Basic::Vector object. This function requires one arguments. Unless nofill is set, the vector will be filled with 0s (assuming the vector wouldn't otherwise be full) on the oldest side of the vector (so an insert will push off one of the filled-zeros). This function returns the object itself, for chaining purposes. set_vector() Given a vector or array ref, this will set the contents (and size) of the vector used for the object computations. This function returns the object itself, for chaining purposes. OVERLOADS
This class provides overloads. If evaluated as a string, it will attempt to print a pretty value for the object (or "n/a", see "query()" above). the resulting string can be tuned, in terms of precision, see ipres for further information. If evaluated as a number, it will try to return the raw result of "query()", possibly turning the resulting "undef" (if applicable) into a 0 in the process -- note that Perl does this 0-izing, not the overload. The "eq" and "==" operators are also overloaded, trying to do the right thing. Also see toler for further information. AUTHOR
Paul Miller "<jettero@cpan.org>" COPYRIGHT
Copyright 2012 Paul Miller -- Licensed under the LGPL SEE ALSO
perl(1), Statistics::Basic, Statistics::Basic::Vector perl v5.14.2 2012-01-23 Statistics::Basic::_OneVectorBase(3pm)
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy