tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: wip/mu: std::getline returning falsy value



> > > This would happen e.g. if the stdin of the program has been closed.
> > 
> > Do you have any ideas of what would cause such a thing to happen? I'm
> > assuming it shouldn't happening since it's in the standard library...
> 
> No, I mean it would probably happen outside of the standard library.
> Below is an example that demonstrates it, it's output looks like:
> 
> --8<--
>  > ./a.out
> hi there
> the line you entered: hi there
> something bad happened to std::cin!
> -->8--
> 
> So the first std::getline() call works fine, but then the fclose(stdin)
> makes the second call fail.
> 
> Martin
> 
> 
> #include <string>
> #include <iostream>
> 
> int main(int argc, char **argv)
> {
> 	std::string aLine;
> 
> 	std::getline(std::cin, aLine);
> 	std::cout << "the line you entered: " << aLine << std::endl;
> 
> 	fclose(stdin);
> 
> 	std::getline(std::cin, aLine);
> 	if (!std::cin) {
> 		std::cout << "something bad happened to std::cin!" << std::endl;
> 		return 1;
> 	}
> 	std::cout << "the line you entered: " << aLine << std::endl;
> 
> 	return 0;
> }

Okay, yes, this makes sense then! I'll take a look around the
codebase to see if I can spot anything of the sort. It may also have
something to do with the project's thirdparty `fmt` library. I
believe it's a vendored version of textproc/fmtlib and I don't see
any obvious way to allow the use of the system's fmtlib.

Thanks again, Martin.

Kev


Home | Main Index | Thread Index | Old Index