댓글 쓰기 권한이 없습니다. 로그인 하시겠습니까?
|
C++
2017.06.07 14:35
istringstream 을 이용한 string type 변환 & 토크나이징
조회 수 19265 댓글 0
istringstream 을 이용하여 새로운 스트림을 만드는 방법. string str("3.14");
istringstream iss(str);
float f;
iss >> f;이 경우에는 f 에 3.14 가 들어간다. 사용하려면 헤더파일 sstream 을 include 시켜주어야 한다. 좀 오래된 컴파일러의 경우 sstream 헤더를 지원하지 않기 한다. strstream 이라는 이름으로 있을지도 모르니 확인必. #include <sstream>
void main()
{
istringstream s("hello 3.13 123");
string name;
float f;
int i;
s>>name>>f>>i;
cout<<f<<name<<i<<endl;
}토크나이징 ng을 사용하는 경우, const char*를 반환하므로 복사가 필요하다. 이럴 때는 std::istringstream을 사용하면 되겠다. std::istringstream issList(response_str);
std::string List;
while (getline(issList, List, ':'))
{
//한번더 토큰
std::istringstream lastissList(List);
std::string lastList;
while (getline(lastissList, lastList, ','))
{
if(lastList.compare("EOF\n")&& lastList.compare("EOF\r\n"))
//appDelegate->g_AMailDataInfo.push_back(lastList);
}
}
Dreamy의 코드 스크랩내가 모으고 내가 보는
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Designed by sketchbooks.co.kr / sketchbook5 board skin
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5