【发布时间】:2011-10-11 21:32:50
【问题描述】:
在 C++ 中我有这个程序:
#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 插入一个字符吗?
【问题讨论】: