In C ++, I have this program:
#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(')'); }
I get the following error:
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>]'
Where do I go from char to const char* ? Can I insert a character at position 0 of a string?
c ++ string pointers
Fahad uddin
source share