THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/06/2012 at 09:15, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R12
Platform: Windows ;
Language(s) : C++ ;
---------
Hi guys,
I need some advice on BaseFile vs. Hyperfile.
I'm trying to read text from a text file. Then store each line of text in an array.
The text in the text file will be listed line-by-line. Think of a list people's last names.
After reading through the archives about how C4D handles text files. I'm finding myself confused on which class is better suited for something like this.
I've already tried using a CHAR method which gets each character in the text file and stores it in a string variable. And then I put that string in a string array.
But now I'm stuck how to "split" that single string element into individual array elements.
I don't see an array split option in the C++ SDK.
Example:
AutoAlloc<BaseFile> bf;
if(!bf) return FALSE;
Filename file = GeGetC4DPath(C4D_PATH_DESKTOP)+Filename("test.txt");
if(!bf->Open(file, FILEOPEN_READ, FILEDIALOG_ANY, BYTEORDER_INTEL, MACTYPE_CINEMA, MACCREATOR_CINEMA)) return FALSE;
String line = "";
LONG fileLength = bf->GetLength(); //Counts how may characters are in the text file
CHAR c[2];
c[1] = 0;
CHAR *pc = &c[0];
for (LONG i = 0L; i != fileLength; ++i) //loop once for each character in the text file
{
bf->ReadChar(pc); //Line read from the file
line += String(pc); //Get the next character
}
bf->Close();
GeDynamicArray<String>textarray(0); //Create the new string type array with 0 blank elements
textarray.Push(line); //Now I have a string array with all the text in the first array element
//How do I split the text into individual array elements?
Am I better off using the hyperfile class to do this?
I've never used that class and I'm finding it a bit confusing to figure out. Because it requires a BaseContainer. And that sounds like the wrong way to go.
But I'm not sure.
-ScottA
P.S.- Why doesn't the SDK have a getline() function for reading text files in it?
That would probably make doing this kind of thing a whole lot easier.