0
을 통해 thread t1
이 입력을 기다리고있는 두 개의 스레드를 시작했습니다. EOF
비트를 cin
에 넣고 thread t2
에서 cin
을 읽을 수 없습니까? 나는 '\n'
과 ios::eofbit
을 시도했다. 둘 다 작동하지 않았다.다른 스레드에서 std :: cin이 더 이상 입력을 읽지 못하게하는 방법은 무엇입니까?
#include <thread>
#include <iostream>
#include <string>
#include <condition_variable>
std::condition_variable cv;
void Foo()
{
std::string sFoo;
std::cin >> sFoo;
// Do stuff with sFoo
}
void Bar()
{
// Do stuff
// If a condition is fullfilled I don't need the input in Foo anymore and so I want to cancel cin.
std::cin.setstate(std::ios::setstate(std::ios::eofbit); // Does not work
std::cin.putback('\n'); // Does not work
// maybe something similar like these above
}
int main()
{
std::thread t1(Foo);
std::thread t2(Bar);
}
가 @KerrekSB 더 cin.close() 함수가 없다 ... 내가 – Mario
를 틀렸다면 정정 해줘 제발 당신 맞아요, 결코 마음 :'시도 @Mario –
-S : 가까운 (STDIN_FILENO) ; 또는':: fclose (stdin);'또는':: close (0);'도 사용할 수 있습니다. http://stackoverflow.com/questions/288062/is-close-fclose-on-stdin-guaranteed-to-be-correct를 참조하십시오. 다소 과감한 내용입니다 ... –