Hi,
I'm trying to do the equivilant of JAVA's
Integer.toStrin g(someInt);
in C++,
I figure there must be something like this since i know you can use
cout or printf to print it, is there a way to not put it to screen just
turn it into a char*?
Thanks! 6 3235
found it....
in the stdlib there's a function called itoa that does exactly that de******@gmail. com wrote: Hi,
I'm trying to do the equivilant of JAVA's
Integer.toStrin g(someInt);
in C++,
I figure there must be something like this since i know you can use cout or printf to print it, is there a way to not put it to screen just turn it into a char*?
Thanks!
use an ostringstream.
#include <sstream>
#include <string>
template<typena me T>
std::string to_string(const T& val)
{
std::ostringstr eam os;
os << val;
return os.str();
}
void f()
{
int x = 7;
std::string s = to_string(x);
}
i use sprintf to do this
<de******@gmail .com> дÈëÓʼþ
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Hi,
I'm trying to do the equivilant of JAVA's
Integer.toStrin g(someInt);
in C++,
I figure there must be something like this since i know you can use cout or printf to print it, is there a way to not put it to screen just turn it into a char*?
Thanks!
Dan wrote: found it....
in the stdlib there's a function called itoa that does exactly that
Erm, no there isn't. It may be in the standard library on your platform,
but it is *not* a standard function.
HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
<de******@gmail .com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Hi,
I'm trying to do the equivilant of JAVA's
Integer.toStrin g(someInt);
in C++,
I figure there must be something like this since i know you can use cout or printf to print it, is there a way to not put it to screen just turn it into a char*? http://www.parashift.com/c++-faq-lit...al-issues.html
Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hc ltech.com>
Kid Hugh wrote: i use sprintf to do this
What size a char[] buffer do you use then?
I dislike the idea of "big enough" char arrays.
IMHO stringstreams are a better choice, unless
you aim for maximum speed.
HTH OP,
- J. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christopher Benson-Manica |
last post by:
I need a smart char * class, that acts like a char * in all cases, but
lets you do some std::string-type stuff with it. (Please don't say to
use std::string - it's not an option...). This is my attempt at it,
but it seems to be lacking... I'm aware that strdup() is nonstandard
(and a bad idea for C++ code) - please just bear with me:
/* Assume relevant headers are included */
class char_ptr
{
|
by: Alex Vinokur |
last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c
> ben19777@hotmail.com (Ben) wrote:
> > 2) Structure casted into an array of char
> > typedef struct {
> > char name;
> > int age;
> > int id;
> > } person;
> >
|
by: Sona |
last post by:
I understand the problem I'm having but am not sure how to fix it. My
code passes two char* to a function which reads in some strings from a
file and copies the contents into the two char*s. Now when my function
returns, the values stored in the char* are some garbage values (perhaps
because I didn't allocate any memory for them).. but even if I allocate
memory in the function, on the return of this function I see garbage..
here is my...
|
by: Peter Nilsson |
last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think
about what the conversion of a char to unsigned char would mean, and whether
it was sensible to actually do so. And pete has raised a doubt in my mind
on the same issue.
Either through ignorance or incompetence, I've been unable to resolve some
issues.
6.4.4.4p6 states...
|
by: jab3 |
last post by:
(again :))
Hello everyone.
I'll ask this even at risk of being accused of not researching adequately.
My question (before longer reasoning) is: How does declaring (or defining,
whatever) a variable **var make it an array of pointers?
I realize that 'char **var' is a pointer to a pointer of type char (I hope).
And I realize that with var, var is actually a memory address (or at
| |
by: GRoll35 |
last post by:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.
All that is suppose to happen is the user enters data and it uses
parent/child class to display it.
here is the 4 errors.
c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char ' to 'char '
|
by: Pedro Pinto |
last post by:
Hi there once more........
Instead of showing all the code my problem is simple.
I've tried to create this function:
char temp(char *string){
alterString(string);
return string;
|
by: Paul Brettschneider |
last post by:
Hello all,
consider the following code:
typedef char T;
class test {
T *data;
public:
void f(T, T, T);
void f2(T, T, T);
|
by: s0suk3 |
last post by:
This code
#include <stdio.h>
int main(void)
{
int hello = {'h', 'e', 'l', 'l', 'o'};
char *p = (void *) hello;
for (size_t i = 0; i < sizeof(hello); ++i) {
|
by: Kenzogio |
last post by:
Hi,
I have a struct "allmsg" and him member :
unsigned char card_number; //16
allmsg.card_number
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |