c ++的ASCII值

时间:2018-03-26 14:38:07

标签: c++

#include <iostream>
using namespace std;

int main()
{
 char c;
 cout << "Enter a character: ";
 cin >> c;
 cout << "ASCII Value of " << c << " is " << string(c);
 return 0;
}

它给了我错误

||=== Build: Debug in circle (compiler: GNU GCC Compiler) ===|
C:\Users\FCI-Laps\Desktop\circle\main.cpp||In function 'int main()':|
C:\Users\FCI-Laps\Desktop\circle\main.cpp|9|error: invalid conversion from 'char' to 'const char*' [-fpermissive]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.tcc|214|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>]' [-fpermissive]|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

1 个答案:

答案 0 :(得分:0)

#include <iostream>
using namespace std;

int main()
{
 char c;
 cout << "Enter a character: ";
 cin >> c;
 cout << "ASCII Value of " << c << " is " << int(c);
 return 0;
}
  

试试这段代码