аргумент типа "wchar_t *" несовместим с параметром типа "char *
#define _CRT_SECURE_NO_WARNINGS
#pragma execution_character_set("utf-8")
#include<TCHAR.H>
#include <format>
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#pragma comment(lib,"Advapi32")
using namespace std;
const char* disk_type[] =
{
"unknown", "no root dir", "removable", "fixed", "remote", "CD-ROM", "RAMDISK"
};
int main()
{
{
cout << "Drives:\n";
DWORD d = GetLogicalDrives();
for (wchar_t disk = 'A'; d; d >>= 1, disk++)
{
if (d & 1)
{
wchar_t root[80] = { 0 };
root[0] = disk;
strcat(root, ":\\");
cout << "Drive " << disk << ": " << disk_type[GetDriveType(root)] << "\n";
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
if (GetDiskFreeSpace( root, &SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters))
{
unsigned long long t = SectorsPerCluster, f;
t *= BytesPerSector; f = t;
t = t * TotalNumberOfClusters / 1024 / 1024;
f = f * NumberOfFreeClusters / 1024 / 1024;
//cout << format("Free space: {0:10lld} of {1:10lld MB}\n", f, t);
cout << format("Free space: {0:10d} of {1:10d} MB\n", f, t);
wchar_t volName[256], fileSystem[256];
if (GetVolumeInformation(root, volName, 256, 0, 0, 0, fileSystem, 256))
{
cout
<< "File system: " << fileSystem << ", volume name: "
<< volName << "\n";
}
}
cout << "\n";
}
}
cout << "----------------8<----------------\n";
}
{
unsigned long long M;
wchar_t Name[256], user[256];
DWORD sz = 256, uz = 256;
if (GetUserName(user, &uz) &&
GetComputerName(Name, &sz) &&
GetPhysicallyInstalledSystemMemory(&M))
{
cout << "Computer \"" << Name << "\" (user name \"" << user
<< "\") has " << M / 1024 << " MB of physical memory\n";
cout << "----------------8<----------------\n";
}
}
{
wchar_t path[300];
if (GetSystemDirectory(path, 300))
cout << "System directory : " << path << "\n";
if (GetWindowsDirectory(path, 300))
cout << "Windows directory: " << path << "\n";
if (GetCurrentDirectory(300, path))
cout << "Current directory: " << path << "\n";
}
}
Ответы (1 шт):
Автор решения: mazik7512
→ Ссылка
wchar_t действительно не совместим с обычным char, ведь он предназначен для 2-байтовых кодировок (и следовательно занимает 2 байта в памяти), в отличии от однобайтового char.
Всё что вам нужно, как правильно указали в комментариях использовать функции для wchar_t.
cout-wcoutstrcat-wcscat
