在下面的代码错误:从“字符”无效的转换为“为const char *
#include <stdlib.h> //atoi
#include <string>
using namespace std;
namespace roman
{
string convert(int input)
{
string inputStr = to_string(input);
if(inputStr.size()==4)
{
return string(atoi(inputStr[0]), 'M')+convert(stoi(inputStr.substr(1, npos)));//error here
}
}
}
我收到名义误差在return
线。我认为它与atoi功能有关。它需要一个const char*
作为输入值。我需要知道如何将inputStr
中的第一个字符变成const char*
。我尝试追加.c_str()
到inputStr[0]
的末尾,但那给了我错误request for member c_str which is of non-class type char
。任何人有一些想法?
错误信息非常清楚。在C++上获取[关于C++的好书](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list),并阅读它。 –