字符串操作:将目录路径中的字符更改为类似于Linux Shell上的目录路径

时间:2020-02-02 03:04:21

标签: c++ linux windows directory c-strings

我正在使用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";





}

0 个答案:

没有答案