<char -> string -> int> char로 받은 후 포인터 변수로 넘겨준 다음 string에 대입한다
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(void)
{
char str[20];
scanf("%s",str);
char *ptr=str;
string a=ptr;
int number=atoi(str);
cout<<number<<endl;
char a[20]="123";
string b=a;
return 0;
}
|
cs |
<string -> char ->int>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int main(void)
{
string a;
cin>>a;
const char *ptr;
ptr=a.c_str();
cout<<ptr<<endl;
return 0;
}
|
cs |
< int ->string or int ->char>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int main(void)
{
int number=230;
char buffer[100];
itoa(number,buffer,10);
cout<<buffer<<endl;
int number=123;
string a=to_string(number);
}
|
cs |
'C++' 카테고리의 다른 글
set< point(클래스) > (0) | 2019.11.22 |
---|---|
set< vector<int> > :: iterator (0) | 2019.11.20 |
연관 컨테이너(Multimap) (0) | 2019.11.10 |
연관 컨테이너(Map) (0) | 2019.11.10 |
memset (0) | 2019.11.07 |