C++ スタイルの文字列を取る関数があります。C ++文字列に入れるかargv[1]
、単に関数に直接渡したいです。
#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>]’