Skip to content

Latest commit

 

History

History
123 lines (69 loc) · 4.75 KB

CppWStrToStr.md

File metadata and controls

123 lines (69 loc) · 4.75 KB

 

 

 

 

 

 

WStrToStr is a convert code snippet to convert a Wt::WString to std::string.

 


///WStrToStr converts a Wt::WString to std::string //From http://www.richelbilderbeek.nl/CppWStrToStr.htm const std::string WStrToStr(const Wt::WString& s) {   return std::string(s.toUTF8()); }

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.4.5
  • Wt Wt: version 3.1.2

 

 

 

 

 

Qt project file: CppWString.pro

 


#------------------------------------------------- # # Project created by QtCreator 2011-04-16T10:24:05 # #------------------------------------------------- QT       += core QT       -= gui LIBS += -lwt TARGET = CppWString CONFIG   += console CONFIG   -= app_bundle TEMPLATE = app SOURCES += main.cpp

 

 

 

 

 

main.cpp

 


#include <cassert> #include <string> #include <Wt/WString> ///StrToWStr converts a std::string to Wt::WString //From http://www.richelbilderbeek.nl/CppStrToWStr.htm const Wt::WString StrToWStr(const std::string& s) {   return Wt::WString(s); } ///WStrToStr converts a Wt::WString to std::string //From http://www.richelbilderbeek.nl/CppWStrToStr.htm const std::string WStrToStr(const Wt::WString& s) {   return std::string(s.toUTF8()); } int main() {   const Wt::WString s = "Hello World";   const std::string t = WStrToStr(s);   const Wt::WString u = StrToWStr(t);   const std::string v = WStrToStr(u);   assert(s == u);   assert(t == v); }