1
대신 :stringstream을 사용하여 >>없이 다음 문자열을 반환하는 방법은 무엇입니까?
stringstream szBuffer;
szBuffer>>string;
myFunc(string);
내가 좋아합니까 방법 :
muFunc(szBuffer.NextString());
난 그냥 함수에 전달하기위한 임시 VAR을 만들 싶지 않다.
대신 :stringstream을 사용하여 >>없이 다음 문자열을 반환하는 방법은 무엇입니까?
stringstream szBuffer;
szBuffer>>string;
myFunc(string);
내가 좋아합니까 방법 :
muFunc(szBuffer.NextString());
난 그냥 함수에 전달하기위한 임시 VAR을 만들 싶지 않다.
당신의 전체 문자열 읽으려면 :
// .str() returns a string with the contents of szBuffer
muFunc(szBuffer.str());
// Once you've taken the string out, clear it
szBuffer.str("");
당신이 (다음 \ n 문자까지) 다음 줄을 추출 할 경우, 사용 istream::getline :
// There are better ways to do this, but for the purposes of this
// demonstration we'll assume the lines aren't longer than 255 bytes
char buf[ 256 ];
szBuffer.getline(buf, sizeof(buf));
muFunc(buf);
의 getline을()는 구분 기호를 두 번째 매개 변수 (기본적으로 \ n)로 사용할 수 있으므로 단어 단위로 읽을 수 있습니다.