473,395 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

plz i want a function convert the "int" to " string"

Hi
i want your help again in c++ !!

i want a function change the "int" to "string"
because in my project "Registration system" in task "b" i must write a course class which contains number of credits and a string id. In addition to the constructor, it should contain a print function..

and the id of course is seprate in 2 part "for example:cs201" thats why i need this function to convert the "int" part to "string" and i found the function sprint but i can not undarstand its work well !! so i want metod more easy than it or if you can explain to me how does it work ??

this my traying to solve

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. class course
  5. {
  6. private:
  7. int credits;
  8. string ID;
  9. static int serialid; 
  10. public:
  11. course (int x, string y)
  12. {char a[10];
  13. sprint(a,"%d" ,serialid)
  14. ID= y+a;
  15. x= creadits;
  16.  
  17. }
  18. void print()
  19. cout<<creadits;
  20. cout<<ID;
  21. }
  22. }; 
  23. course::serialid=1;
  24.  
Nov 12 '07 #1
6 2678
sicarie
4,677 Expert Mod 4TB
Warly girl-

Please read this section for use of code tags, and use them in the future. Thanks.
Nov 12 '07 #2
i am sorry . i will try to be best in the future .
sorry again but i realy can not use clear english in my qustion
i like this fourm
it is best than arabic fourm that i visit always
i think that i am student in this fourm
and i think also that all person will pe patient to my bad language
i am in level 1 . plz don not prevent me to learn here just because of my week language .....

thanks
Nov 12 '07 #3
toefraz
19
It's pretty simple. Just use the itoa function with the cstdlib header.

Example:

Expand|Select|Wrap|Line Numbers
  1. int number = 1200;
  2. char numArray[10];    //Size of 10 should be good, can increase if needed.
  3. itoa(number, numArray, 10); //10 is for the base.
  4. string str = numArray; //Convert to a string (requires string header)
Nov 12 '07 #4
Ganon11
3,652 Expert 2GB
If you prefer to not use the legacy C function, you can use a stringstream:

Expand|Select|Wrap|Line Numbers
  1. stringstream ss;
  2. string myStr;
  3. int myNum = 12345;
  4.  
  5. ss << myNum;
  6. ss >> myStr;
  7. //myStr now equals "12345"
Nov 12 '07 #5
toefraz
19
That's cool. I didn't know such a thing existed. I'll have to read up on stringstreams.
Nov 12 '07 #6
sorry about my late
&
Thanke you very much
Nov 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that...
7
by: ma740988 | last post by:
The string object value_f doesn't produce the right output. At issue, - I suspect - is the conversion from string to int with istringstream. An alternate approach? Thanks in advance #include...
5
by: Stuart | last post by:
Ok let me explain: I am writing a c# program that calls into an unmanaged C++ third-party DLL. I have to make a number of calls and for simplification the protype I am calling is: bool fn(int...
2
by: privetv7 | last post by:
ppl... HELP!!!!! i don't know how to convert String into char..... for example i can do String input; int number; input = JOptionPane.showInputDialog( "Enter what ever" ); number =...
3
by: Petr Jakes | last post by:
Hi, I am trying to convert string to the "escaped string". example: from "0xf" I need "\0xf" I am able to do it like: a="0xf" escaped_a=("\%s" % a ).decode("string_escape") But it looks a...
16
by: ondekoza | last post by:
Hello, I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: >>> 0xffffffff -1 >>> 0xffffffffL 4294967295L OK, this is what I want, so I tried
10
by: R2d2Rabeau | last post by:
Hi, I'm new to C#, please be patient :-) I am trying to pass an Arraylist (myAL) to a jagged array (myAL2) . The problem I have is that when I write the values to a file i do not get the values...
6
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. ...
1
by: khgoh | last post by:
Hi, Need help for the error "OverflowError: long int too large to convert to int" while reading a zip file content. Python version: Python 2.4.1 (#1, Sep 13 2005, 00:39:20) on linux2 Code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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...

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.