我有一个采用 c++ 样式字符串的函数。我想要么放入argv[1]
一个 c++ 字符串,要么直接将它传递给我的函数。
#include <iostream>
#include <string>
using namespace std;
string rev (string &reverse);
int main(int argc, char argv[])
{
if (argc != 2)
cout << "Bad Input" << endl;
string reverse = argv[1];
cout << rev(reverse) << endl;
}
这是我到目前为止所拥有的,但是当我这样做时,我收到以下错误:
8.4.cpp: In function ‘int main(int, char*)’:
8.4.cpp:11: error: invalid conversion from ‘char’ to ‘const char*’
8.4.cpp:11: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’