Jump to content
  • Advertisement
Sign in to follow this  
precious roy

C++ text to int question

This topic is 3495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi every one, I’ve just started programming in c++ and was wondering how would you convert a in to string an back ? I’m programming without the standard libraries. any ideas. Roy

Share this post


Link to post
Share on other sites
Advertisement
If you're posting in "For Beginners" trying to program without the standard library is not a particularly sane methodology.

In any case, you can either use boost::lexical_cast or a std::stringstream.

std::stringstream sstr;
sstr << my_int;
std::string str1 = sstr.str();

std::string str2 = boost::lexical_cast<std::string>(my_int);

Share this post


Link to post
Share on other sites
Quote:

I’m programming without the standard libraries.

Is there any particular reason for doing so? I mean, even input and output are going to cause trouble with such a mindset.

Share this post


Link to post
Share on other sites
Well this is every thing i'm using

#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>


its off a tutorial from.

http://www.directxtutorial.com

and i dont wat to use .net

Share this post


Link to post
Share on other sites
Quote:
Original post by precious roy
Well this is every thing i'm using

#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>


its off a tutorial from.

http://www.directxtutorial.com


You know that you're allowed to include more header files than what a tutorial says, right? You're not going to hurt yourself by experimenting. [smile]


#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>
#include <sstream> //Gasp, we can use stringstreams now!

Share this post


Link to post
Share on other sites
thank you veryy mutch.. you have opend new dors for me :}

but one more question how would i convert string to LPCWSTR

Most web sites say that this should work

int i = 1;
std::stringstream sstr;
sstr<<i;
std::string test = sstr.str();

d3dfnt->DrawText(NULL, test.c_str(), -1, &rct, 0, TextColor );

but it gives a can not convert error.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!