ark1974 ark1974 - 4 months ago 50
C++ Question

Max character length for serialization of folder path

I search stackoverflow for the answer but can't get a close match. I am serializing contents of a drive. I am using boost::filesystem::path for the manipulation. What should be the maximum ( 300 is just nominal) char length to store the path information in windows OS.

struct raw_event
friend std::ifstream& operator >> (std::ifstream& infile, raw_event& raw);
friend std::ofstream& operator << (std::ofstream& outfile, raw_event& raw);

char path_[300];


Windows maximum path is 260, unless you're using the Unicode API. Then it is 32767. Source MSDN Not sure what Boost uses, but you do not want to always store 32k just to be sure. There are times to nuke the site from orbit. This isn't one of them.

To do a variable length string, I usually go Pascal style and write the length of the string to the file and then write the string, but that is for binary files. For a text file, as suggested by operator<< in the question, you are better off using a delimiter like quotes and std::getline.