showTitle("https://tistory1.daumcdn.net/tistory/520789/skin/images/", "viewTitle.swf", 600, 30, "seekg(0, ios::beg) doesn't work!", "/entry/%EC%A0%9C%EB%AA%A9%EC%9D%84-%EC%9E%85%EB%A0%A5%ED%95%B4-%EC%A3%BC%EC%84%B8%EC%9A%94", "left", "#000000");
2010. 11. 28. 02:08
Programming/C++
C++에서 ifstream으로 파일을 읽다가 다시 그 위치를 처음으로 돌리고 싶을때
가끔 is.seekg(0, ios::beg); 이게 먹히지 않는 경우가 발생한다.
처음에는 결국 해결 방법을 못 찾아서 파일을 닫고 다시 열어서 읽었던 기억이있다.
혹시나 다음과 같은 경우라면 해결 방법이 있다.
다음-> 파일을 끝까지 읽어 EOF(End Of File) 까지 간경우 bad() state 이기 때문에 clear()를 seekg 전에 써줘야 한다.
- data.clear();
- data.seekg(0);
Since you've gone till the EOF, the stream is now in a bad() state. You need to clear() it before you can seekg():
Reference : http://www.gamedev.net/community/forums/topic.asp?topic_id=447865
가끔 is.seekg(0, ios::beg); 이게 먹히지 않는 경우가 발생한다.
처음에는 결국 해결 방법을 못 찾아서 파일을 닫고 다시 열어서 읽었던 기억이있다.
혹시나 다음과 같은 경우라면 해결 방법이 있다.
다음-> 파일을 끝까지 읽어 EOF(End Of File) 까지 간경우 bad() state 이기 때문에 clear()를 seekg 전에 써줘야 한다.
- data.clear();
- data.seekg(0);
Since you've gone till the EOF, the stream is now in a bad() state. You need to clear() it before you can seekg():
Reference : http://www.gamedev.net/community/forums/topic.asp?topic_id=447865
'Programming > C++' 카테고리의 다른 글
C++을 하면서 자주 쓰는 구문들.. (0) | 2010.11.29 |
---|---|
#define, #ifdef, #ifndef, #endif (0) | 2010.03.28 |
Header에서 #pragma once Vs #ifndef (0) | 2010.03.28 |
#pragma once (why it is always attached when we making new class file in visual studio? (0) | 2010.03.28 |
union(공용체)와 BitField (0) | 2010.03.14 |