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 7723969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:34:38+00:00 2026-06-01T04:34:38+00:00

I am getting a compilation error. I am trying to add strings to a

  • 0

I am getting a compilation error. I am trying to add strings to a vector and keep them in “sorted order”.

XYZ is my class. addPortEntry

class XYZ
{
    public:
        portListFile(string sTmp);
        void addPortEntry(string sPortName, string sDirection);
    private:
        string sPortListFileName;
        vector <string> v_input_ports;
    ...
};

void XYZ::addP(string sP, string sDir)
{
    if(sDir == "in")
    {
        v_input_ports.insert(sP);   // Line 42
    }
    ...
}

Error:

XYZ.cpp: In member function ‘void XYZ::addP(std::string, std::string)’:
XYZ.cpp:42: error: no matching function for call to ‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::insert(const char [10])’
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:93: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:657: note:                 void std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]
  • 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-06-01T04:34:39+00:00Added an answer on June 1, 2026 at 4:34 am

    insert should be given an iterator to insert at a certain location. You need to use push_back instead (which is the same as insert with end() as parameter).

    edit

    You mentioned in the comments:

    I do not want to use push_back since I want the strings to be sorted.
    That is one of the reasons I’m using the vector

    I miss the logic in that statement. If you want a sorted container you should be using either std::set or std::map. Use the “multi-” versions if you want repeating values.

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

Sidebar

Related Questions

I am getting a compilation error when trying to build a C++ project which
I am getting an compilation error not a statement for the below code. Not
I am getting a compilation error for the following statement: void read_text(int & c1,
I'm getting an error when trying to create the linked list that says: Exception
I'm trying install pycrypto on osx with easy_install and I'm getting the following error:
I'm trying to extend Page class to add some new functionality (ease of use
I'm getting this error message when trying to to use the RPC XML with
I am getting the following error when trying to access a WCF service. Could
In the following code i am getting compilation error:c2227:left of -> left must point
Probably the following cannot be done (I am getting a compilation error: The inherited

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.