How to change the language standard to c++17

The problem I encountered is related to the fact that unreal engine 4.27 uses c++14 by default and filesystem was added in the c++17 standard. Since I don’t want to change the standard library to boost, I’m trying to update the c++ standard to c++17 in my project on unreal engine 4.27. But everywhere it says about CMakeLists.txt and Build.bat which I don’t have. when opening the properties of the file with the name of my project in visual studio and changing the text in the most similar line “nmake/additional parameters” from /std:c++14 to /std:c++17, the error C2039 “filesystem is not a member of std” did not disappear. most likely, the language standard is changed somewhere in the project settings inside Unreal Editor, but I couldn’t find it. just in case, I’ll say right away that I have declared the library include . and I will attach the code of the function that the compiler swears at.
function code:
void ASubReader::CreateDirect(FString Path, int& Out) { string route(TCHAR_TO_UTF8(*Path)); std::filesystem::path Folder(route);

if (!std::filesystem::exists(Folder)) { // Проверка, существует ли уже папка с таким путем
	if (std::filesystem::create_directory(Folder)) { // Создание папки
		Out = 0;
	}
	else {
		Out = 1;
	}
}
else {
	Out = 2;
}

}
init code:
UFUNCTION(BlueprintCallable) void CreateDirect(FString Path, int& Out);

are you compiling from source?
there should be checks in the Compilation Tool Chain that check for the C++ version, so the checks that call out C++14 or older would be in there.

If you are using the installed engine then your out of luck and will probably need to migrate your project to a newer engine version to get the library changes.

the other option would be to find something similar to <std::Filesystem> for C++14 and append that to the engine.

though if your trying to just do fileIO then are you sure that the existing functionality doesn’t already work:

  • FFileHelper gives Read/Write using byte arrays
  • FFileHandle Read/Write of Binaries
  • TTextFileHelper Read/Write of “text” files
  • FJsonObjectholding and working with JSON
  • TPlatformFile interface for “platform-independent” that abstract file system

all of these are available in 4.27 already.

1 Like

according to what this code gave me

#if __cplusplus >= 202002L
Out = 20;
#elif __cplusplus >= 201703L
Out = 17;
#elif __cplusplus >= 201402L
Out = 14;
#elif __cplusplus >= 201103L
Out = 11;
#elif __cplusplus >= 199711L
Out = 98;
#else
Out = 1611;
#endif

my c++ version is older than the 2011 version. I will try to find another universal library for creating folders

if you want to make sure a Folder path exists then use FPath
if you want to potentially create a folder then look into PlatformFileManager

if the folder is going to be in your games directory then you can mark the folder as an asset for the asset manager, and then have it included in the Cooking process.

these are things that have been “needed” since UDK 3 days so they still exist in the engine. they just might not be using parts of the Standard Library to do it.

be mindful that if you are targeting console you may fail certification if for creating files outside of your directory, and mobile has its own storage concerns.

the solution was found by my friend on the Internet on this site. if you add a line

CppStandard = CppStandardVersion.Cpp17;

to the "projectname".Build.cs, the library starts working, but this does not affect the version of the standard itself and is not displayed in the function cplusplus

my Build.cs file after adding the line

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class GpsTestV2 : ModuleRules
{
public GpsTestV2(ReadOnlyTargetRules Target) : base(Target)
{
	CppStandard = CppStandardVersion.Cpp17;

	PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

	PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

	PrivateDependencyModuleNames.AddRange(new string[] {  });

	// Uncomment if you are using Slate UI
	// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

	// Uncomment if you are using online features
	// PrivateDependencyModuleNames.Add("OnlineSubsystem");

	// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true

}
}
1 Like