forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversions.cpp
50 lines (40 loc) · 1.29 KB
/
conversions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// to_string() , sto_() works for everything except char
#include<iostream>
using namespace std;
void ANY_to_string(){
int x=23; double y=3.14; char ch='A';
string si=to_string(x); //int to string (string si=x is wrong)
string sd=to_string(y); //double to string
string sc=""; sc=sc+ch; //char to string
//string sc=""+ch; //string+string ✓ , string+char X in initialisation only. Else ✓
//string sc=to_string(ch); stores ASCII value of char instead of original
cout<<si<<endl<<sd<<endl<<sc<<endl;
}
void string_to_ANY(){
string si="23", sd="3.140000", sc="A";
int x=stoi(si); //string to int (int x=si is wrong)
double y=stod(sd); //string to double
char ch=sc[0]; //string to char
//char ch=stoc(ch) doesn't exist
//∵ string to char is not possible since char variable can't accept multiple characters
//But string to char array is possible
cout<<x<<endl<<y<<endl;
}
void REST_not_concerning_strings(){
//int <-> char
//int <-> double
//double <-> char
//(rest)
//all done by TYPECASTING
}
void ArraytoString(){
char ch[]={'C','+','+','\0'};
string s=string(ch);
cout<<s<<endl;
}
int main(){
ANY_to_string();
string_to_ANY();
REST_not_concerning_strings();
ArraytoString();
}