|
Prev: C++ Vs C#
Next: Help Using WinDBG
From: Jack on 5 Jun 2006 03:50 How do I convert an integer to std::string? Thanks Jack
From: ramyasangeet@gmail.com on 5 Jun 2006 04:19 Jack wrote: > How do I convert an integer to std::string? > Thanks > Jack Using MFC: Convert int to string int x=12345; CString s; // s = "" (empty string) s.Format("%d", x); // s = "12345" as string Convert string to int int x=0; CString s="12345"; x = atoi(s); // x= 12345 as integer Regards, sangeet
From: Jack on 5 Jun 2006 04:22 <ramyasangeet(a)gmail.com> ???????:1149495568.894697.301610(a)g10g2000cwb.googlegroups.com... > > Jack wrote: > >> How do I convert an integer to std::string? >> Thanks >> Jack > > Using MFC: > Convert int to string > int x=12345; > CString s; // s = "" (empty string) > s.Format("%d", x); // s = "12345" as string > Dear Sangeet, Thanks for replying. But I regret to say that the target object type is std::string rather than CString std::string is standardised strings while CString is VC specific. Thanks Jack > > Convert string to int > int x=0; > CString s="12345"; > x = atoi(s); // x= 12345 as integer > > Regards, > sangeet >
From: David Wilkinson on 5 Jun 2006 05:57 ramyasangeet(a)gmail.com wrote: > Jack wrote: > > >>How do I convert an integer to std::string? >>Thanks >>Jack > > > Using MFC: > Convert int to string > int x=12345; > CString s; // s = "" (empty string) > s.Format("%d", x); // s = "12345" as string > > > Convert string to int > int x=0; > CString s="12345"; > x = atoi(s); // x= 12345 as integer > > Regards, > sangeet > Jack: Two possible methods: int x = 0; std::ostringstream os; os << x; std::string str = os.str(); or int x = 0; CString s; s.Format("%d", x); std::string str = s; The boost librray also has some ways to do this. David Wilkinson
From: Jack on 5 Jun 2006 06:01 "David Wilkinson" <no-reply(a)effisols.com> ???????:ehwN7ZIiGHA.1612(a)TK2MSFTNGP04.phx.gbl... > ramyasangeet(a)gmail.com wrote: > >> Jack wrote: >> >> >>>How do I convert an integer to std::string? >>>Thanks >>>Jack >> >> >> Using MFC: >> Convert int to string >> int x=12345; >> CString s; // s = "" (empty string) >> s.Format("%d", x); // s = "12345" as string >> >> >> Convert string to int >> int x=0; >> CString s="12345"; >> x = atoi(s); // x= 12345 as integer >> Regards, >> sangeet >> > > Jack: > > Two possible methods: > > int x = 0; > std::ostringstream os; > os << x; > std::string str = os.str(); > > or > > int x = 0; > CString s; > s.Format("%d", x); > std::string str = s; > > The boost librray also has some ways to do this. > > David Wilkinson Dear David, It's all great, Thanks Jack > >
|
Pages: 1 Prev: C++ Vs C# Next: Help Using WinDBG |