-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathStringConversion.cpp
32 lines (26 loc) · 1005 Bytes
/
StringConversion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define _CRT_SECURE_NO_WARNINGS
#include <cstdlib>
#include <string>
#include <Windows.h>
std::string to_string(const std::string& str) {
return str;
}
std::string to_string(const std::wstring& wstr) {
std::string str(wstr.size(), 0);
std::wcstombs(&str[0], wstr.c_str(), wstr.size());
return str;
}
std::wstring to_wstring(const std::string& str) {
std::wstring wstr(str.size(), 0);
std::mbstowcs(&wstr[0], str.c_str(), str.size());
return wstr;
}
std::wstring to_wstring(const std::wstring& wstr) {
return wstr;
}
int main() {
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), to_string("Hello, World1 !\n").c_str(), 16, nullptr, nullptr);
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), to_string(L"Hello, World2 !\n").c_str(), 16, nullptr, nullptr);
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), to_wstring("Hello, World3 !\n").c_str(), 16, nullptr, nullptr);
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), to_wstring(L"Hello, World4 !\n").c_str(), 16, nullptr, nullptr);
}