x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Read and Write data from text file

Is it possible to read and write data from a text file for example use the text files data ( exampletext ) and store it as a variable Player->Name = file; out put = hello, exampletext

if that is understandable :/

Product Version: Not Selected
Tags:
more ▼

asked Aug 24 '14 at 08:59 PM in C++ Programming

avatar image

AndrewM47
262 68 61 78

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

CoreMisc.h

All the functionality you want is in CoreMisc.h

 /**
      * Write the FString to a file.
      * Supports all combination of ANSI/Unicode files and platforms.
      */
     static bool SaveStringToFile( const FString& String, const TCHAR* Filename, EEncodingOptions::Type EncodingOptions=EEncodingOptions::AutoDetect, IFileManager* FileManager=&IFileManager::Get() );
 
 
 /**
      * Load a text file to an FString.
      * Supports all combination of ANSI/Unicode files and platforms.
      * @param Result string representation of the loaded file
      * @param Filename name of the file to load
      * @param VerifyFlags flags controlling the hash verification behavior ( see EHashOptions )
      */
     static bool LoadFileToString( FString& Result, const TCHAR* Filename, uint32 VerifyFlags=0 );
 
 
 
 /**
      *    Load the given ANSI text file to an array of strings - one FString per line of the file.
      *    Intended for use in simple text parsing actions
      *
      *    @param    InFilename            The text file to read, full path
      *    @param    InFileManager        The filemanager to use - NULL will use &IFileManager::Get()
      *    @param    OutStrings            The array of FStrings to fill in
      *
      *    @return    bool                true if successful, false if not
      */
     static bool LoadANSITextFileToStrings(const TCHAR* InFilename, IFileManager* InFileManager, TArray<FString>& OutStrings);

Sample Usage:

You call the functions statically

 FFileHelper::SaveStringToFile(...);
 
 FFileHelper::LoadANSITextFileToStrings(...);

CPP Source Code For You

I use the above functions in my Victory BP Library plugin, whose entire source code is available with the download (no cost)

https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required!

Enjoy!

Rama

more ▼

answered Aug 24 '14 at 09:27 PM

avatar image

Rama
10.6k 446 345 1088

avatar image Hayaweh Oct 12 '14 at 01:19 PM

thanks a lot. This is exactly what I was searching for! :) (and that's quite an impressive work you made, congrats) :)

avatar image Dragon Slave Feb 05 '19 at 11:08 PM

These C++ commands are now found in:

> Core/Public/Misc/FileHelper

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Just want to add that the WriteFlags refered from FFileHelper::SaveStringToFile can be found(i think/hope) in FileManager.h :

 enum EFileWrite
 {
     FILEWRITE_NoFail            = 0x01,
     FILEWRITE_NoReplaceExisting = 0x02,
     FILEWRITE_EvenIfReadOnly    = 0x04,
     FILEWRITE_Append            = 0x08,
     FILEWRITE_AllowRead            = 0x10
 };

The default behaviour is rewrite the file with the Fstring. If you want to add Fstring to the same file you will make a call with 0x08 inside the flags. Remember that the new line is LINE_TERMINATOR and you should be ready to go! Hope can be useful, being almost a total newbie to Unreal c++ this could saved me some time :)

more ▼

answered Jun 15 '16 at 11:37 AM

avatar image

Eymrich
59 1 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi !

I trying to write it to the text file from UE4 version 4.11. Does this method still work on it ? If yes , how ?

Thank!

more ▼

answered Jun 18 '16 at 03:02 PM

avatar image

yanjieng
0 1 1

avatar image Xanitsu Aug 17 '16 at 02:14 PM

Yes it does you would use the "file IO save string array to file" node. It also works with 4.12 and 4.13 (i think). I am not sure how to read the files though.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Yes it still work

more ▼

answered Jan 18 '19 at 12:07 PM

avatar image

lillydr1scoll
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question