Pergunta

I am writing a c++ program that executes shell commands. I am using the popen() function to run the commands. I would like my exec function to return std::string but I do not know how to read from a FILE into a string. Is there a way to do this without reading into a char[] first and then converting that into a string? If there are many which is the most efficient?

Foi útil?

Solução

It is not possible. The popen() function returns a pointer to a FILE. You cannot read from a FILE directly into std::string. You can however convert char* to std::string which appears to be the best solution in your case.

Outras dicas

It sounds like you could use std::ifstream --> http://www.cplusplus.com/doc/tutorial/files/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top