비교적 간단한 문자열 조작을하기 위해 C++ stringstream 클래스를 사용하려고 시도했지만 get() 메소드에 문제가 있습니다. 어떤 이유로 출력 문자를 문자로 추출 할 때마다 최종 문자의 두 번째 사본이 추가됩니다.C++ stringstream이 여분의 문자를 반환합니까?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
stringstream ss("hello");
char c;
while(!ss.eof()) {
ss.get(c);
cout << "char: " << c << endl;
}
return 0;
}
프로그램의 출력은 다음과 같습니다이 감사하겠습니다에
char: h
char: e
char: l
char: l
char: o
char: o
어떤 도움을 당신이 내게 줄 수 있습니다.
예, 오타입니다. #include은 #include이어야합니다. –
Chris