'C++: GetTempPath() without tilde (~)

I need to get temp path. So I tried GetTempPath() and std::getenv("TEMP"). The problem is that the result contains ~ symbol, for example C:\Users\OLEKSI~1.ALE\AppData\Local\Temp. Is it possible to get full temp path like C:\Users\Oleksii\AppData\Local\Temp?



Solution 1:[1]

According to the Microsoft documentation:

The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

  • The path specified by the TMP environment variable.
  • The path specified by the TEMP environment variable.
  • The path specified by the USERPROFILE environment variable.
  • The Windows directory.

Have you checked what these are set to? In Windows 10 you can press Windows+Break to open System Settings, then click Advanced system settings on the right, then click Environment Variables. If TMP, TEMP or USERPROFILE are in there, check that they are set correctly and don't have the unwanted ~ in them. If they're not, try adding them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1