通过调用c+;列出Linux系统的所有用户名+;功能 < >我想通过调用某个库中的C++函数来获取POSIX系统的所有用户名称。找到了唯一的选择,使用C++程序中的调用BASH命令,如< P> > P> POSIX通过以下功能提供这个功能: #include <iostream> #include <sys/types.h> #include <pwd.h> int main() { while (true) { errno = 0; // so we can distinguish errors from no more entries passwd* entry = getpwent(); if (!entry) { if (errno) { std::cerr << "Error reading password database\n"; return EXIT_FAILURE; } break; } std::cout << entry->pw_name << '\n'; } endpwent(); } #包括 #包括 #包括 int main(){ while(true){ errno=0;//因此我们可以将错误与其他条目区分开来 passwd*entry=getpwent(); 如果(!输入){ 如果(错误号){ std::cerr

通过调用c+;列出Linux系统的所有用户名+;功能 < >我想通过调用某个库中的C++函数来获取POSIX系统的所有用户名称。找到了唯一的选择,使用C++程序中的调用BASH命令,如< P> > P> POSIX通过以下功能提供这个功能: #include <iostream> #include <sys/types.h> #include <pwd.h> int main() { while (true) { errno = 0; // so we can distinguish errors from no more entries passwd* entry = getpwent(); if (!entry) { if (errno) { std::cerr << "Error reading password database\n"; return EXIT_FAILURE; } break; } std::cout << entry->pw_name << '\n'; } endpwent(); } #包括 #包括 #包括 int main(){ while(true){ errno=0;//因此我们可以将错误与其他条目区分开来 passwd*entry=getpwent(); 如果(!输入){ 如果(错误号){ std::cerr,c++,linux,C++,Linux,POSIX通过以下函数提供此功能: #include <iostream> #include <sys/types.h> #include <pwd.h> int main() { while (true) { errno = 0; // so we can distinguish errors from no more entries passwd* entry = getpwent(); if (!

POSIX通过以下函数提供此功能:

#include <iostream>
#include <sys/types.h>
#include <pwd.h>

int main() {
    while (true) {
        errno = 0; // so we can distinguish errors from no more entries
        passwd* entry = getpwent();
        if (!entry) {
            if (errno) {
                std::cerr << "Error reading password database\n";
                return EXIT_FAILURE;
            }
            break;
        }
        std::cout << entry->pw_name << '\n';
    }
    endpwent();
}
#包括
#包括
#包括
int main(){
while(true){
errno=0;//因此我们可以将错误与其他条目区分开来
passwd*entry=getpwent();
如果(!输入){
如果(错误号){

STR: C++不了解Linux,它是独立于OS的。你需要使用系统调用或获得一个库。也许你正在寻找。“NaNaOLIVER同意我编辑我的问题+ +不知道Linux,它是独立于OS的。你需要使用系统调用或得到一个库。也许你在寻找?”NaNaulver同意我编辑。我的问题这正是我要找的!谢谢!这正是我要找的!谢谢!