Skip to content

Instantly share code, notes, and snippets.

@DennisOSRM
Created June 27, 2013 19:13
Show Gist options
  • Save DennisOSRM/5879466 to your computer and use it in GitHub Desktop.
Save DennisOSRM/5879466 to your computer and use it in GitHub Desktop.
Load street names of the planet file
std::vector<std::string> names;
std::ifstream namesInStream(namesPath.c_str(), std::ios::binary);
if(!namesInStream) { return -1; }
unsigned size(0);
namesInStream.read((char *)&size, sizeof(unsigned));
char buf[1024];
for(unsigned i = 0; i < size; ++i) {
unsigned sizeOfString = 0;
namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
buf[sizeOfString] = '\0'; // instead of memset
namesInStream.read(buf, sizeOfString);
names.push_back(buf);
}
std::vector<std::string>(names).swap(names);
namesInStream.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment