在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