Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ostringstream to tchar*

ostringstream to tchar*

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AksharRoop
    wrote on last edited by
    #1

    Hiya, It would be helpful if someone tell me how I could convert ostringstream to tchar* such that it will work in both ansi and unicode compilation. currently i have done like:

    std::ostringstream strn;
    strn <<"Just do it!";
    const TCHAR* tata = static_cast< LPCTSTR >(strn.str().c_str());

    But this does not seems to work in both the cases.

    N 1 Reply Last reply
    0
    • A AksharRoop

      Hiya, It would be helpful if someone tell me how I could convert ostringstream to tchar* such that it will work in both ansi and unicode compilation. currently i have done like:

      std::ostringstream strn;
      strn <<"Just do it!";
      const TCHAR* tata = static_cast< LPCTSTR >(strn.str().c_str());

      But this does not seems to work in both the cases.

      N Offline
      N Offline
      Nuri Ismail
      wrote on last edited by
      #2

      I'd use something like:

      // Handle both unicode and ansi builds
      #ifdef _UNICODE
      typedef std::wstring tstring;
      typedef std::wostringstream tostringstream;
      #else
      typedef std::string tstring;
      typedef std::ostringstream tostringstream;
      #endif

      //......

      tostringstream strn;
      strn << _T("Just do it!");
      tstring str = strn.str();
      const TCHAR* tata = str.c_str();

      modified on Wednesday, May 12, 2010 8:48 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups