473,471 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

int to string convert ???

Hello !

How to convert int value to string in QT or ANSI C++ library ?

please help

skyer
Jul 22 '05 #1
4 8275

"skyer" <po****@re-comp.com.pl> wrote in message
news:bu**********@atlantis.news.tpi.pl...
Hello !

How to convert int value to string in QT or ANSI C++ library ?

please help

skyer


http://www.parashift.com/c++-faq-lit....html#faq-38.1
Jul 22 '05 #2
"skyer" <po****@re-comp.com.pl> wrote in message
news:bu**********@atlantis.news.tpi.pl...
Hello !
How to convert int value to string in QT or ANSI C++ library ?

The C standard library function itoa (IntegerToAlpha) is what you're looking
for.

#include <iostream> // cout
#include <cstdlib> // itoa(), system()
using namespace std;

int main(void){ // command line unused
int myNumber = 42;
char myCharString[15]; // empty string 15 char long

cout << "value of myNumber is: " << myNumber << endl
<< "myCharString contains: " << myCharString << endl; // empty

// use itoa (IntegerToAlpha) to convert to string equivalent
itoa( myNumber, myCharString, 10 ); // the 10 is the number base
cout << "myCharString contains: " << myCharString << endl;

// use a different number base
itoa( myNumber, myCharString, 16 ); // hex
cout << "myCharString, base-16: " << myCharString << endl;

system("pause"); // wait for keypress
}
Jul 22 '05 #3

"skyer" <po****@re-comp.com.pl> wrote in message
news:bu**********@atlantis.news.tpi.pl...
Hello !

How to convert int value to string in QT or ANSI C++ library ?

please help

skyer


Try using the stringstreams..
In the below code, the error handling is excluded for readability..

#include <iostream>
#include <sstream>

template<class T> void ConvertFromStringA(const char* pszStringRep,T&
retVal);
template<class T> std::string ConvertToStringA(const T& val);

template<class T> void ConvertFromStringA<T>(const char* pszStringRep,T&
retVal)
{
std::istringstream ist(pszStringRep);
ist >> retVal;
}

template <class T> std::string ConvertToStringA(const T& val)
{
std::ostringstream ost;
ost << val;
return ost.str();
}
Jul 22 '05 #4
AngleWyrm wrote:
The C standard library function itoa (IntegerToAlpha) is what you're looking
for.

There is no such standard function, though it is a common extension, and
therefore off-topic here.

For C++, use a stringstream.

Brian Rodenborn
Jul 22 '05 #5

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

Similar topics

3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
2
by: Mike P | last post by:
I need a way of encrypting strings that provides a fairly high level of encryption. I've looked at System.Security.Cryptography at...
7
by: Eric | last post by:
Hi All, I need to XOR two same-length Strings against each other. I'm assuming that, in order to do so, I'll need to convert each String to a BitArray. Thus, my question is this: is there an...
5
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography ...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
0
by: Jim Langston | last post by:
pradeep wrote: Not big enough by far and disappears once IntToString finishes. No reason to have to do this. sprintf( buf, "%d", i ); would also work, although there are hte other...
28
by: pradeep | last post by:
Hello friends: I know some people here don't like to answer C++ questions, but I believe this is really about the underlying C code. Anyway I have posted as well to the other group someone...
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
6
by: aznimah | last post by:
hi, i'm work on image comparison. i'm using the similarity measurement which i need to: 1) convert the image into the binary form since the algorithm that i've use works with binary data for the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.