반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- @State
- IOS
- operator
- RxCocoa
- NavigationLink
- URL(string:)
- @Binding
- RFC1738/1808
- graphql
- Operators
- nestjs
- NullObject
- swift6
- nonisolated
- SWIFT
- @EnvironmentObject
- RxSwift
- typeorm
- init?
- SwiftUI
- ios14
- dismiss
- Operater
- @Environment
- subject
- Xcode
- init
- Bug
- Creating Operators
- vim
Archives
- Today
- Total
Tunko Development Diary
std::string -> int [std::stoi 사용] 본문
// stoi example
#include <iostream> // std::cout
#include <string> // std::string, std::stoi
int main ()
{
std::string str_dec = "2001, A Space Odyssey";
std::string str_hex = "40c3";
std::string str_bin = "-10010110001";
std::string str_auto = "0x7f";
std::string::size_type sz; // alias of size_t
int i_dec = std::stoi (str_dec,&sz);
int i_hex = std::stoi (str_hex,nullptr,16);
int i_bin = std::stoi (str_bin,nullptr,2);
int i_auto = std::stoi (str_auto,nullptr,0);
std::cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";
std::cout << str_hex << ": " << i_hex << '\n';
std::cout << str_bin << ": " << i_bin << '\n';
std::cout << str_auto << ": " << i_auto << '\n';
return 0;
}
output
2001, A Space Odyssey: 2001 and [, A Space Odyssey] 40c3: 16579 -10010110001: -1201 0x7f: 127
반응형
'Development > C++, C++11' 카테고리의 다른 글
숫자 자리수별 심볼 표시하기 K, M, G, T, P (0) | 2017.11.08 |
---|---|
std::vector erase 사용하기 (0) | 2017.10.18 |
std::string 형변환 정리. (0) | 2017.10.11 |
std::string 문자열의 마지막 문자 가져오기 (0) | 2017.10.11 |
Comments