【发布时间】:2018-03-26 15:01:08
【问题描述】:
#include <iostream>
using namespace std;
int main()
{
char x;
cout << "enter a character:";
cin >> x;
cout << "ASCII Value of " << x << "is" << string(x);
return 0 ;
}
错误是
main.cpp||In function 'int main()':|
main.cpp|10|error: invalid conversion from 'char' to 'const char*'|
main.cpp|10|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>]'|
||=== Build finished: 2 errors, 0 warnings ===|
【问题讨论】:
-
returb 0 ;->return 0 ; -
x 不是
const char*或char*那么为什么std::string(x)可以工作? -
std::string的构造函数没有带字符。 -
请为您的问题添加更多描述,例如您要做什么、预期的输出以及您得到的输出。