0

I have multiple text files with different names, which I'd like to read into a struct I defined in a header file (working in Unreal Engine 4). These text files all contain multiple lines, all containing a name as well as 3 file locations which I'd like to have free access to. This is my struct:

struct FName
{

GENERATED_BODY()

UPROPERTY()   FString name;
UPROPERTY()   FString data_path;
UPROPERTY()   FString model_path;
UPROPERTY()   FString coll_path;

}

These files look like this:

EXAMPLE NAME1, \USERCONTENT\DATA1, \USERCONTENT\MODEL1, \USERCONTENT\COL1
EXAMPLE NAME2, \USERCONTENT\DATA2, \USERCONTENT\MODEL2, \USERCONTENT\COL2
etc

I know that I have to:
-get a list of all files in the directory
-iterate through all of them, and save this data to a my struct.

Number 1 is pretty easy, filesystem and dirent can do both, but 2) is a massive headache for me (I've searched online but to no avail, I need it as a struct, not a string). Any ideas?

Anon1216
  • 1
  • 1
  • Do any of these similar questions help? https://stackoverflow.com/questions/27098305/parsing-string-into-struct-variables https://stackoverflow.com/questions/50676902/string-to-struct-in-c https://stackoverflow.com/questions/27661311/how-to-parse-string-into-numbers-in-known-struct-c https://stackoverflow.com/questions/50263176/how-to-parse-string-to-struct https://stackoverflow.com/questions/27807662/c-split-string-and-use-it-for-struct – Stef Dec 01 '20 at 14:16
  • Or more likely: https://stackoverflow.com/questions/236129/how-do-i-iterate-over-the-words-of-a-string/236803#236803 https://stackoverflow.com/questions/23047052/why-does-reading-a-record-struct-fields-from-stdistream-fail-and-how-can-i-fi – Stef Dec 01 '20 at 14:17
  • So after parsing my data into a string (called data for example), I'd simply do as the first question said and go: `void parse_string(string data) { istringstream iss(data); for (size_t i=0; iss >> FName.at(i).name; ++i) { iss >> Fname.at(i).data_path >> Fname.at(i).model_path >> Fname.at(i).coll_path; } }` Something like that? Sorry if it doesn't make much sense, this is all relatively new to me – Anon1216 Dec 01 '20 at 14:36

0 Answers0