Answer the question
In order to leave comments, you need to log in
Why are there two newlines at the end of the function response and how to remove them?
THE CODE:
string python_shell(string code) {
string command = "py -c " + code;
FILE* fp = _popen(command.c_str(), "r");
if (fp) {
std::vector<char> buffer(4096);
std::size_t n = fread(buffer.data(), 1, buffer.size(), fp);
if (n && n < buffer.size()) {
buffer.data()[n] = 0;
return buffer.data();
}
_pclose(fp);
}
}
int main(){
cout <<python_shell("print("")").c_str()<< endl;
return NULL;
}
ПУСТАЯ СТРОКА 1
ПУСТАЯ СТРОКА 2
КУРСОР
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question