Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- VARCHAR (1)
- 오블완
- Spring Batch
- table not found
- terminal
- 코루틴 컨텍스트
- 겨울 부산
- tolerated
- 티스토리챌린지
- vfr video
- PersistenceContext
- mp4fpsmod
- 깡돼후
- 개성국밥
- JanusWebRTC
- JanusWebRTCServer
- 달인막창
- preemption #
- 코루틴 빌더
- k8s #kubernetes #쿠버네티스
- 자원부족
- kotlin
- Value too long for column
- JanusGateway
- PytestPluginManager
- python
- pytest
- taint
- JanusWebRTCGateway
Archives
너와 나의 스토리
[C++] freopen()한 후 cin 무시되는 상황 해결 본문
반응형
void readInputFile0(hash_t *H) {
FILE *fp0=freopen("input0.txt","r",stdin);
while (cin >> input_key >> input_item) {
int res = hash_insert(H, input_key, input_item);
}
if (fclose(fp0) == 0) {
cout << "input0파일 정상적으로 닫혀짐\n";
}
else {
cout << "input0파일 정상적으로 안 닫힘\n";
}
fclose(fp0);
fp0 = stdin;
return;
}
void main(){
readInputFile0(H);
while(cin>>tmp){
//cin 안되고 tmp 초기화 값으로 계속 유지됨
}
}
처음에 이런식으로 했더니 main에서 입력이 먹지 않았다.
입력 버퍼 비워야 하나.... 해서
cin.clear();
cin.ignore();
이런거 써보고....
결과는 fail!
검색해보니 freopen은 C I/O라서 C++이랑 섞어써서 이런 문제가 생긴 것 같다
그래서 freopen 대신 ifstream으로 바꿔서 써 주었다.
void readInputFile0(hash_t *H) {
ifstream input("input0.txt");
while (input >> input_key >> input_item) {
int res = hash_insert(H, input_key, input_item);
}
input.close();
return;
}
cin 대신 ifstream 객체로 입력 받아야함
해결!
반응형
'Programming Language' 카테고리의 다른 글
[C++] 클래스(class)와 구조체(struct ) (0) | 2020.02.18 |
---|---|
[프로그래밍 언어론] CH7 Expressions and Assignment Statements (0) | 2019.12.04 |
[프로그래밍 언어론] CH6 Subprograms (0) | 2019.12.04 |
[프로그래밍 언어론] CH9 Subprograms (0) | 2019.12.03 |
[프로그래밍 언어론] Ch8 Statement-Level Control Structures (0) | 2019.12.01 |
Comments