英文:
error C3861: popen, pclose: identifier not found in c++
问题
I get the error "error C3861: popen: identifier not found", if I run through vs code then everything works, but if I run through Microsoft Visual Studio, then the program does not want to compile. How to fix it?
code (C++):
#include <iostream>
#include <string>
#include <cstdlib>
int main() {
std::string result = "";
FILE* pipe = popen("some command 2>&1", "r"); //error
char buffer[128];
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe); //error
std::cout << "res: " << result;
return 0;
}
英文:
I get the error "error C3861: popen: identifier not found", if I run through vs code then everything works, but if I run through microsoft vs then the program does not want to compile. How to fix it?
code (c++):
#include <iostream>
#include <string>
#include <cstdlib>
int main() {
std::string result = "";
FILE* pipe = popen("some command 2>&1", "r"); //error
char buffer[128];
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe); //error
std::cout << "res :" << result;
return 0;
}
答案1
得分: 4
如果您使用Windows,可能会使用_popen()和_pclose()。
尝试这样做:
FILE* pipe = _popen("some command 2>&1", "r");
英文:
If you are on Windows, it might be _popen() and _pclose()
Try this:
FILE* pipe = _popen("some command 2>&1", "r");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论