以下は私のコードです(C++)...私はgetusername
で取得したユーザー名をメイン関数に戻す方法を混乱させています。誰もがナイスのヒントや提案を持っていますか?文字列をmain int関数に戻す方法は?
#include <iostream>
//For the strings obviously
#include <string>
using namespace std;
string getusername();
string user;
string getusername() {
user = system("echo %username% > NUL");
return user;
}
int main() {
string getname;
getname = getusername();
cout << "Hello: "<< getname << endl;
}
私はVisual Studioを使用していますが、エラーは返されませんでした...出力はユーザー名を返すことはありません...ちょうど 'Hello:'と言います。 – NerdOfCode
[std :: system() '](http://en.cppreference.com/w/cpp/utility/program/system)関数が実際に何を行うのかをお読みください。 – user0042
値を取得しますか?環境変数 '%username%'? ['std :: getenv()'](http://en.cppreference。com/w/cpp/utility/program/getenv)を実行します。 – user0042