devc++输入中文字符逆序输出
时间: 2023-12-18 14:29:53 浏览: 35
以下是使用Dev C++实现将输入的中文字符逆序输出的程序:
```cpp
#include <iostream>
#include <string>
#include <locale>
int main() {
std::wstring str;
std::wcout << L"输入一个字符串:" << std::endl;
std::getline(std::wcin, str);
std::wstring reversedStr;
for (int i = str.length() - 1; i >= 0; i--) {
reversedStr += str[i];
}
std::wcout << L"逆序输出结果:" << reversedStr << std::endl;
system("pause");
return 0;
}
```
相关问题
c++实现字符串逆序输出
可以使用C++的string类和reverse函数实现字符串逆序输出,具体代码如下:
```c++
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "Hello World!";
reverse(str.begin(), str.end()); // 使用reverse函数逆序字符串
cout << str << endl;
return 0;
}
```
输出结果为:`!dlroW olleH`。
C++逆序输出字符串
以下是两种C++逆序输出字符串的方法:
1.使用for循环逆序输出字符串
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "hello world";
for (int i = str.length() - 1; i >= 0; i--) {
cout << str[i];
}
return 0;
}
// 输出:dlrow olleh
```
2.使用reverse函数逆序输出字符串
```cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str = "hello world";
reverse(str.begin(), str.end());
cout << str;
return 0;
}
// 输出:dlrow olleh
```