Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:01:27+00:00 2026-05-31T04:01:27+00:00

void insert_string( std::vector<std::string> & strings, const std::string &s ) { std::vector<std::string>::iterator it=lower_bound(strings.begin(),strings.end(),s); if(strings.size()>0) std::cout<<*it<<

  • 0
void insert_string( std::vector<std::string> & strings, const std::string &s )
{

    std::vector<std::string>::iterator it=lower_bound(strings.begin(),strings.end(),s);
    if(strings.size()>0) std::cout<<*it<<" is found\n"; // ****
    strings.insert(it,s);
}

When attempting to use this function, the first insertion goes fine. The second insertion will output “[firststring] is found” and then segfault. If I comment out the if/cout line, I can repeatedly call and no segfaults occur.

I’ve also tried doing something like std::string tmp=*it; which will then segfault on that line. While printing is not a huge deal, what I’m really trying to do is check if the string at the position found by lower_bound is the same as the string that is trying to be inserted (i.e., if(*it==s), which is segfaulting just like the above two examples).

What am I missing here?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:01:28+00:00Added an answer on May 31, 2026 at 4:01 am

    Check for the condition if it == strings.end(), if it is don’t print it. This could cause the issue. Are you sure the string you’re trying to check is in the vector of strings?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this function: template<typename T> void Inventory::insertItem(std::vector<T>& v, const T& x) { std::vector<T>::iterator
class MyObject{ public: void testFunctionMap(){ std::unordered_map<std::string, std::function<void()> > functionMap; std::pair<std::string, std::function<void()> > myPair(print, std::bind(&MyObject::printSomeText,
So imagine we had 2 functions (void : ( void ) ) and (std::string
VERSION 1 class Doh { private: static std::map<const std::string, const Doh*> someMap; std::string stringValue_;
In code: template<class T,int row, int col> void invert(T (&a)[row][col]) { T* columns =
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;
#include <tuple> #include <vector> #include <string> #include <iostream> //------------------------------------------------------------------------- #include <boost/spirit/include/karma.hpp> #include <boost/fusion/adapted/std_tuple.hpp> //-------------------------------------------------------------------------
Environment: VS2005 C++ using STLPort 5.1.4. Compiling the following code snippet: std::string copied =
These lines of code are run: Enemy* enemy = new Enemy(m_pSceneManager,enemy+ss.str()); std::cout << Enemy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.