Hi
i want your help again in c++ !!
i want a function change the "int" to "string"
because in my project "Registrati on 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 -
#include<iostream>
-
#include<string>
-
using namespace std;
-
class course
-
{
-
private:
-
int credits;
-
string ID;
-
static int serialid;
-
public:
-
course (int x, string y)
-
{char a[10];
-
sprint(a,"%d" ,serialid)
-
ID= y+a;
-
x= creadits;
-
-
}
-
void print()
-
cout<<creadits;
-
cout<<ID;
-
}
-
};
-
course::serialid=1;
-
6 2695 sicarie 4,677
Recognized Expert Moderator Specialist
Warly girl-
Please read this section for use of code tags, and use them in the future. Thanks.
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
It's pretty simple. Just use the itoa function with the cstdlib header.
Example: - int number = 1200;
-
char numArray[10]; //Size of 10 should be good, can increase if needed.
-
itoa(number, numArray, 10); //10 is for the base.
-
string str = numArray; //Convert to a string (requires string header)
Ganon11 3,652
Recognized Expert Specialist
If you prefer to not use the legacy C function, you can use a stringstream: - stringstream ss;
-
string myStr;
-
int myNum = 12345;
-
-
ss << myNum;
-
ss >> myStr;
-
//myStr now equals "12345"
That's cool. I didn't know such a thing existed. I'll have to read up on stringstreams.
sorry about my late
&
Thanke you very much
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
influence which integral type you choose:
|
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 <iostream>
#include <sstream>
#include <string>
using namespace std;
|
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 *pResult);
This result is used by other subsequent functions that I
have to call.
Q: Is it possible to call this function from C# declaring
|
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 = Integer.parseInt(input)
|
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 little bit complicated in this beautiful language to me
.....
| |
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
|
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 instead I get "System.String" ? How can I fix the problem? I wanted to use ArralyList because its length is flexible and I can add values to it.
...All help will be greatly appreciated.
Here's my code:
|
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. Here's a very
simple example which should illustrate what I'm doing.
#include <iostream>
template <class T>
class TestBase
{
|
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
>>> import os, datetime, sys, optparse, string, operator, gzip
>>> health_day_summary_file = gzip.GzipFile( "health_CORR_summary.csv.gz", "rb")
|
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |