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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:53:07+00:00 2026-06-18T01:53:07+00:00

For some reason my source file will not compile because of my toString function.

  • 0

For some reason my source file will not compile because of my toString function. It claims it cannot recognize the + symbol to append strings. Here’s my code:

string s = "{symbol = " + symbol + ", qty = " + qty + ", price = " + price + "}";

symbol, qty, and price are variables in the class

I get the following message from the compiler…

CLEAN SUCCESSFUL (total time: 55ms)

mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/Stock.o.d
g++    -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/Stock.o.d -o build/Debug/GNU-MacOSX/Stock.o Stock.cpp
Stock.cpp: In member function 'std::string Stock::toString()':
Stock.cpp:56: error: no match for 'operator+' in 'std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)", qty = ")) + ((Stock*)this)->Stock::qty'
make: *** [build/Debug/GNU-MacOSX/Stock.o] Error 1


BUILD FAILED (exit value 2, total time: 261ms)

Anyone know what’s going on here?

  • 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-18T01:53:09+00:00Added an answer on June 18, 2026 at 1:53 am

    You can’t call std::string::operator+ on int types, use std::stringstream

    #include <sstream>
    #include <string>
    
    std::stringstream ss;
    ss << "{symbol = " << symbol << ", qty = " << qty << ", price = " << price << "}";
    
    std::string s = ss.str();
    

    Or use std::to_string if you use C++11 and boost::lexical_cast to cast integer types to string first:

    std::string s = "{symbol = " + symbol + ", qty = " + std::to_string(qty) 
                    + ", price = " + std::to_string(price) + "}";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason beyond me my html page is not finding my stylesheet. I'm
From the good_enc function in the format.c file within the libmpg123 source. It is
I cannot for some reason get the wordpress /wp-admin pages to execute a simple
Is there some way to source an R script from the web? e.g. source('http://github.com/project/R/file.r')
I'm trying to write up a function which will post data (and append the
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason I can't detect I can't set a z index for any
For some reason there's a variable called d that is defined immediately after I
For some reason the postback event keeps firing for my button. If I place

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.