String.Insert

Discussion in 'C++' started by meyup, May 29, 2010.

  1. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    hi!
    I try to grade in the following as the characters to examine a srings.
    So the program is to put every one at the store in a vector e occurs, then one every e E insert before ..
    Code:
    #include <iostream.h> 
    #include <string.h> 
    #include <vector.h> 
    
    int main() 
      { 
       string test="dies ist der Test string"; 
       int counter=0; //zähler der wegen der string vergrösserung gebraucht wird 
       vector<int> V; 
      
       for(int i=0;i<=test.length();i++) { 
          if(test[i]=="e") { 
             V.push_back(i); 
            } 
         } 
       for(int j=0;j<=V.size();j++) { 
          test.insert(V[j+counter],"E"); 
          counter+=1; 
         } 
    cout << test; 
    
       return 0; 
      }
    but I get the run is always a serious error of .. because a white area violates why or how else I can do that?
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    http://ipankaj.net
    try it this way:
    Code:
    for (int j = 0; j <= V.size () j + +) ( 
    test.insert (V [j] + counter, "E") 
    counter + = 1; 
    )
     
  3. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    would need to go there! I am an idiot! this is also evident !!!!!
    thank you! I'll have a test tomorrow ..
     
  4. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    First of all, it should in clean C + + look like this
    Code:
    #include <iostream> 
      #include <string> 
      #include <vector> 
      using namespace std;
     
  5. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    :-(

    it's not imernoch! still the same errors.


    "Project Project1.exe raised exceptin class _STL:: out_of_range with message 'Exception Object Address: 0xCB32C6."

    HEELP!
     
  6. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    hmm think about it you go one

    for (int j = 0; j <V.size();j++) statt for(int j=0;j<=V.size();j++)
    and to examine if (test == 'e') not to "e"
     
  7. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    yoo! thanks! that's it
    :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice