64,683
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string>
std::string&& test(const std::string& str)
{
printf("1: 0x%08x\n", str.c_str());
std::string tmp(str);
printf("2: 0x%08x\n", tmp.c_str());
return std::move(tmp);
}
int main()
{
const std::string in("右值引用测试!");
printf("0: 0x%08x\n", in.c_str());
printf("3: 0x%08x\n", test(in).c_str());
return 0;
}
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
std::vector<char>&& UnicodeToAnsi(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return std::move(std::vector<char>());
std::vector<char> utf8(len);
::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);
printf("0x%x\n", &utf8[0]);
return std::move(utf8);
}
std::string&& test(const std::string& str)
{
printf("1: 0x%08x\n", str.c_str());
std::string tmp(str);
printf("2: 0x%08x\n", tmp.c_str());
cout << tmp << endl;
return std::move(tmp);
}
int main()
{
std::vector<char>& ret = UnicodeToAnsi(L"okokjfijeiljsiefjlsifjlisef");
cout << ret.size() << endl;
printf("0x%x\n", &ret[0]);
const std::string in("test!");
printf("0: 0x%08x\n", in.c_str());
std::string& rs = test(in);
printf("3: 0x%08x\n", rs.c_str());
cout << rs << endl;
return 0;
}