将LPCTSTR转换为std::string

LPCTSTR folder_path; char str[1024]; wsprintfA(str, "%S ",folder_path); string str_(str);

去掉string的空格:

#include <iostream> #include <string> #include <boost/algorithm/string.hpp> using namespace std; using namespace boost; int main() { string s = " hello boost!! "; trim(s); cout << s << endl; }

string与wstring之间有转换:

#include <string> #include <algorithm> // Prototype for conversion functions std::wstring StringToWString(const std::string& s); std::string WStringToString(const std::wstring& s); std::wstring StringToWString(const std::string& s) { std::wstring temp(s.length(),L' '); std::copy(s.begin(), s.end(), temp.begin()); return temp; } std::string WStringToString(const std::wstring& s) { std::string temp(s.length(), ' '); std::copy(s.begin(), s.end(), temp.begin()); return temp; } using namespace std; int main() { string s1 = "Hello"; wstring s2 = StringToWString(s1); s1 = WStringToString(s2); return 0; }

相关文章:

  • 2022-12-23
  • 2021-12-22
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-07-21
  • 2021-05-22
相关资源
相似解决方案