C++ text to int question

Started by
14 comments, last by nobodynews 14 years, 11 months ago
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
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);
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.
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
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!
Using the Standard C++ Library has nothing to do with .Net libraries.
hmm ok

now i know that... thanks

is ther a way to find out witch header suports what ???
Yes; Google. If you search for the header name, you should be able to find a list of classes and functions it exposes.
Here and here. These are two sites that you will find frequently at the top of a Google search for a SC++L feature.
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.

This topic is closed to new replies.

Advertisement