hey, had a question that I couldn't figure out. I'm writing a program for linux and I need to save things to a person's Desktop. Because of that, I need to know their username. I am aware of the linux commands whoami, id, etc, but they only print the current user's name, not return it so I can use it in the program. Is there any way to put in a variable what is put on the screen (and hopefully prevent it from being printed to the screen in the first place).
#include<iostream>
using namespace std;
int main()
{
std::string name;
name = system("whoami");
cout << "Name is : " << name;
cout << endl;
return 0;
}
output:
user@user-desktop:~$ /home/user/Desktop/test
user
Name is :
user@user-desktop:~$
Thanks!
~J