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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:49:30+00:00 2026-06-13T11:49:30+00:00

So I have a function, where KaylesPosition is a class with a vector<int> called

  • 0

So I have a function, where KaylesPosition is a class with a vector<int> called piles:

// Produces a key to compare itself to equivalent positions     
std::string KaylesPosition::makeKey(){
  std::vector<int> temp(piles.size());
  for (int i = 0;i<piles.size();i++){
    temp[i]=piles[i];
  }

  std::sort (temp.begin(),temp.end());
  std::string key = "" + temp.at(0);
  for (int i=1 ; i<temp.size() ; i++){
    key.push_back('.');
    key.push_back(temp.at(i));
  }

  return key;
}

My expected output should be all of the elements in piles in order, separated by periods. However instead, I get key return as “_M_range_check”. I have tried this using std::string.append() and I get either an empty string or a period. How do I get this function to return a string of all of the values in piles as expected?

  • 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-13T11:49:31+00:00Added an answer on June 13, 2026 at 11:49 am

    The problem seems to be here:

    key.push_back(temp.at(i));
    

    You are trying to append an integer to a string without getting the string representation of the integer first. Try replacing that line with:

    key += std::to_string(temp.at(i)); // This will only work if your compiler supports C++11
    

    If your compiler doesn’t support C++11, try this (don’t forget to #include <sstream>):

    std::ostringstream o;
    o << temp.at(i);
    key += o.str();
    

    Or, if you have the option to use Boost (http://boost.org/ ), try its lexical_cast:

    key += boost::lexical_cast<std::string>(temp.at(i));
    

    The reason this code compiled in the first place, is because push_back accepts a char as its parameter and you’re passing an int which gets converted to char (although I would expect a warning from the compiler in this case).

    P.S.: Same applies for the line

      std::string key = "" + temp.at(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function which takes in an parameter of a class called Triple, and
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
This is driving me crazy: I have function void gst_init(int *argc, char **argv[]); in
I have function like this typedef vector<vector<string> > vecArray; vecArray dul(); vecArray dul() {
I have function as below: foo :: Int -> a -> [a] foo n
I have function in my database class that returns the id of the people
I have function called getdoctor () in asmx file I wannna call this webmethod
I have function with simple sql query to list tickets on the page: class
I have function which append div (help icon) after all element with .help class.
Assume that i have function called PlaceOrder , which when called inserts the order

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.