C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 26th, 2003, 02:24 PM
particleman particleman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 6 particleman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
C++ itoa function gives me errors

Hello:

This is what I am trying to do, assign an integer to a string so for instance:

int myInt=5;
string myStr;

myStr=myInt;

and I want myStr to have "5". So I am using the "itoa()" function of the format:

#include <cstdlib>

char* itoa( int value,
char* buffer,
int radix );

and I know that that I am implementing it properly. I am running two compilers, Metrowerks code warrior on windows and G++ on Linux, so when I compile the code on the windows machine it works fine but on the Linux machine (which is my first priority) I get this error:

implicit declaration of function `int itoa(...)'

What am I doing wrong? I googled quite a bit and found some people saying that it might be a bug, but that they werent sure. so is there a way that I can use that function in G++?

Thanx!

Reply With Quote
  #2  
Old September 27th, 2003, 03:30 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Do you really need it in a variable? Why not just do:
PHP Code:
 int simple_number 5;
    
printf("I am only %d years old\n"simple_number); 
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old October 1st, 2003, 05:15 AM
Lothver Lothver is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 8 Lothver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 50 sec
Reputation Power: 0
I have no problems with the use of the itoa() function. Here is the simple test code i compiled. Written in MSVisual C++

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

void main()
{
int i=12; // number to be converted
string s; // string to recive the number
char b[50]; // buffer of chars
int radix=10; // 2:bin, 8:octal, 10:dec, 16:hex
s=itoa(i,b,radix);
cout << "int i=" << s << endl;
cout << "buffer=" << b << endl;
}

Reply With Quote
  #4  
Old October 5th, 2003, 08:47 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
You've included the header <cstdlib>.

That's correct, except you've forgotten that everything in cstdlib is defined in the std namespace. So, you can do the following (which I don't recommend):

Code:
using namespace std;


Either of the two methods below is recommended, although the first is preferred. The reason is that they don't clutter up the global namespace with std classes, functions and variables, and thus defeat the purpose of a namespace.

You can specify the namespace explicitly when you call itoa(), like so (preferred):

Code:
std::itoa(MyInt)


Or, even this:

Code:
using std::itoa

// Now I don't need the full std::itoa() call,
// but I haven't imported everything in std either.
itoa(MyInt);


Hope that sets you on track.
__________________
Jeb.

AIM: JebediahMc - PM Me - E-Mail Me


Last edited by Jeb. : October 5th, 2003 at 09:06 PM.

Reply With Quote
  #5  
Old January 1st, 2005, 10:41 PM
cmsenthil cmsenthil is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 cmsenthil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes

Yes that worked. I had the same problem with printf and strncmp

got the error:
implicit declaration of function int printf(...)

Now it works!

Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ itoa function gives me errors


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap