반응형
ostream을 표준 문자열로 변환
저는 C ++ STL을 처음 접했으므로 사소한 것일 수 있습니다. ostream
텍스트 가있는 변수가 있습니다.
ostream* pout;
(*pout) << "Some Text";
스트림을 추출하여 유형의 문자열에 저장하는 방법이 char*
있습니까?
std::ostringstream stream;
stream << "Some Text";
std::string str = stream.str();
const char* chr = str.c_str();
그리고 한 시간 전에 쓴 이 질문 에 대한 답에서 무슨 일이 일어나고 있는지 설명합니다 .
질문은 ostream
문자열이 아니라 문자열 에 관한 것이 었습니다 ostringstream
.
실제 질문에 대한 답변에 관심이있는 분은 다음을 ostream
시도해보십시오.
void someFunc(std::ostream out)
{
std::stringstream ss;
ss << out.rdbuf();
std::string myString = ss.str();
}
std::ostringstream os;
os<<"Hello world";
std::string s=os.str();
const char *p = s.c_str();
참고 URL : https://stackoverflow.com/questions/3513173/converting-ostream-into-standard-string
반응형
'Program Tip' 카테고리의 다른 글
tcpdump를 사용하여 HTTP 요청, 응답 헤더 및 응답 본문을 가져올 수 있습니까? (0) | 2020.12.02 |
---|---|
오류없이 Symfony2 잘못된 양식 (0) | 2020.12.02 |
SPAN_EXCLUSIVE_EXCLUSIVE와 같은 Span 플래그의 의미를 설명하십시오. (0) | 2020.12.02 |
UITableView 배경 이미지 (0) | 2020.12.02 |
post increment 연산자가 int를 반환하는 메서드에서 작동하지 않는 이유는 무엇입니까? (0) | 2020.12.02 |