블로그 이미지
Starrysky1101

Tag

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
  • total
  • today
  • yesterday
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

posted by Starrysky1101