473,563 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert from int to std::string

int iAnno = 2005;
int iMes = 7;
int iDia = 23;

std::stringstre am ssAnno;
ssAnno << iAnno;
std::string anno = ssAnno.str();

std::stringstre am ssMes;
ssMes << iMes;
std::string mes = ssMes.str();

std::stringstre am ssDia;
ssDia << iDia;
std::string dia = ssDia.str();

std::string fecha= anno + mes + dia;
Jun 27 '08 #1
5 3973
On Mon, 19 May 2008 01:40:59 -0700, rtrujillor wrote:
int iAnno = 2005;
int iMes = 7;
int iDia = 23;

std::stringstre am ssAnno;
ssAnno << iAnno;
std::string anno = ssAnno.str();

std::stringstre am ssMes;
ssMes << iMes;
std::string mes = ssMes.str();

std::stringstre am ssDia;
ssDia << iDia;
std::string dia = ssDia.str();

std::string fecha= anno + mes + dia;
So what is the question from your side?

--
Umut
Jun 27 '08 #2
rt********@gmai l.com wrote:
int iAnno = 2005;
int iMes = 7;
int iDia = 23;

std::stringstre am ssAnno;
ssAnno << iAnno;
std::string anno = ssAnno.str();

std::stringstre am ssMes;
ssMes << iMes;
std::string mes = ssMes.str();

std::stringstre am ssDia;
ssDia << iDia;
std::string dia = ssDia.str();

std::string fecha= anno + mes + dia;
template<typena me T, typename F T StrmConvert( const F from )
{
std::stringstre am temp;
temp << from;
T to = T();
temp >to;
return to;
}

template<typena me Fstd::string StrmConvert( const F from )
{
return StrmConvert<std ::string>( from );
}

int iAnno = 2005;
int iMes = 7;
int iDia = 23;

std::string fecha = StrmConvert(iAn no) + StrmConvert(iMe s) +
StrmConvert(iDi a);
--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #3
Hi!

Jim Langston schrieb:
template<typena me T, typename F T StrmConvert( const F from )
{
std::stringstre am temp;
temp << from;
T to = T();
temp >to;
return to;
}

template<typena me Fstd::string StrmConvert( const F from )
{
return StrmConvert<std ::string>( from );
}
Which is a simple copy of boost::lexical_ cast :)

Frank
Jun 27 '08 #4
Frank Birbacher wrote:
Jim Langston schrieb:
> template<typena me T, typename F T StrmConvert( const F from )
{
std::stringstre am temp;
temp << from;
T to = T();
temp >to;
return to;
}

template<typena me Fstd::string StrmConvert( const F from )
{
return StrmConvert<std ::string>( from );
}

Which is a simple copy of boost::lexical_ cast :)
boost::lexical_ cast also does error checking so that it can throw
boost::bad_lexi cal_cast. IIRC it checks failbit and whether the stream
has arrived at EOF or not (to catch cases such as "12a").
--
Christian Hackl
Jun 27 '08 #5
Hi!

Christian Hackl schrieb:
boost::lexical_ cast also does error checking so that it can throw
boost::bad_lexi cal_cast. IIRC it checks failbit and whether the stream
has arrived at EOF or not (to catch cases such as "12a").
Yes, correct. It is much more sophisticated and also supports conversion
from A to B where neither is a string.

Regards, Frank
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
48645
by: Karthik | last post by:
Hello, How can I convert a BSTR data type to std::string??? Thanks a much! Karthik
16
16396
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
8
12136
by: ppcdev | last post by:
Here's what I try : LPCTSTR tst = (LPCTSTR) (LPCWSTR) Marshal::StringToHGlobalUni(str); c:\MyNetPrj\Prj0001\stunt.cpp(244): error C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'LPCWSTR' I really get mad with that !!!
10
26581
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char* and I want to give it a std::string no matching function for call to `MD5::update(std::string&, size_t)' candidates are: void MD5::update(unsigned...
2
12150
by: Abhishek | last post by:
how to do convert a std::string to LPTSTR (chat *) datatype regards Abhishek
10
10097
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's Appendix D recommendation won't compile in Microsoft VC++ 6.0). My question is in reference to MultiByte Character Sets. Will this code perform as...
7
12267
by: varsha.gadekar | last post by:
I want to convert the message of type RWCString to std::string type. How can we do this?
3
40596
by: timor.super | last post by:
Hi group, how to convert a string to a vector of unsigned char ? I used to iterate trough the string to set the vector, but I think this is not the best way to do this. I'm a beginner with the STL How about allocating the vector ? should I know before the size ? And I would like to do then opposite conversion, from an unsigned char
11
5039
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
4
17335
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7943
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3631
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
912
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.