在C转换无效++我有这样的程序:C++,从 '字符' 到 '为const char *'
#include <iostream>
using namespace std;
int main(){
string expression_input;
cout << "User Input: " << endl;
getline(cin, expression_input);
expression_input.insert(0, '('); //error happens here.
expression_input.append(')');
}
我收到以下错误:
prog.cpp:15: error: invalid conversion from ‘char’ to ‘const char*’
prog.cpp:15: error: initializing argument 2 of
‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT,
_Traits, _Alloc>::insert(typename _Alloc::rebind<_CharT>::other::size_type,
const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>,
_Alloc = std::allocator<char>]’
我在哪里,我转换从char
到const char*
?我不能在字符串的位置0插入一个字符吗?
-1:你当然可以使用'insert'和'char'。你只需要使用它的一个不同的重载。 –
我想我没有提到它不适用于使用签名他使用的字符串::插入函数 – minus