我正在使用Visual Studio 2019并且使用Windows7。我想知道如何获取打开C ++文件的当前目录(编译为exe文件时),并使目录路径看起来像Linux Shell目录。路径(例如,将\
更改为/
)。我目前正在使用以下C ++代码:
#include <iostream>
using namespace std;
#include <windows.h>
#include <Lmcons.h>
#include<stdio.h>
int main()
{
//Variables
TCHAR name[UNLEN + 1];
CHAR hostname[UNLEN + 1];
DWORD size = UNLEN + 1;
TCHAR hname[UNLEN + 1];
DWORD hsize = UNLEN + 1;
//Username
if (GetUserName((TCHAR*)name, &size))
{
wcout << L"[" << name << L"@";
//PC Name
if (GetComputerName((TCHAR*)hname, &hsize))
{
wcout << hname << L" ]# ";
}
}
else
//Not required
cout << "Hello, unnamed person!\n";
}