0

So basically i need to replace the first digit of the 'temperature', if its '1', to either a '2' or a '0'. i haven't gotten to the zero part of the code yet i am just stuck on the first replace function. for what ever reason i keep getting an error stating that theres "no matching member function for call to 'replace'". not sure what i could be doing wrong. I have changed the user inputted int "temp" to a string "sTemp" and am able to determine if the first character of the string is in fact a 1 or not. But again getting error on replace.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main() {
    int temP;
    string sTemp;
    stringstream ss;


    cout << "Enter the temperature desired: " << endl;
    cin >> temP;

    ss << temP;
    ss >> sTemp;

    if (sTemp[0] == '1')
        sTemp.replace(0, 1, '2');


    return 0;
    }
Marc K
  • 261
  • 3
  • 8
  • 23
Kyle Joeckel
  • 469
  • 2
  • 9
  • I highly doubt that the problem is that a function in the C++ standard library is failing in its basic functionality, as your question title suggests - but, if this is what you suspect, you should specify what compiler you're using. – Ben Mar 05 '16 at 01:06
  • well do you see anything wrong with the code? i have no idea what to problem is i just was stating the error i was given. But i am running Mac with eclipse mars. – Kyle Joeckel Mar 05 '16 at 01:13
  • Maybe I'm going about this wrong? its also saying that i can not change a char to a constant char. HELP PLEASE!!! – Kyle Joeckel Mar 05 '16 at 01:45

1 Answers1

1

'char' is different from "string" in C++. Double quotes denote a char[] while single quotes denote a char. In other words, you need to provide a string to the function.

Replace the single quotes with double quotes.

CinchBlue
  • 6,046
  • 1
  • 27
  • 58