loadStrings()
Input / FilesDescription
Reads the contents of a file and creates a vector of strings, one per line.
Syntax
std::vector<std::string> loadStrings(std::string path)
Parameters
| Name | Type | Description |
|---|---|---|
| path | std::string | path to the file |
Returns
std::vectorRelated
Under the Hood
From Processing.h:
inline std::vector<std::string> loadStrings(const std::string& path) {
std::vector<std::string> lines; std::ifstream f(path); std::string l;
while (std::getline(f,l)) lines.push_back(l);
return lines;
}
static std::vector<std::string> loadStrings(const std::string& path);
Under the Hood
From Processing.cpp:
std::vector<std::string> PApplet::loadStrings(const std::string& path) {
std::vector<std::string> lines;
std::string sketchDir;
if (const char* sp = std::getenv("PROCESSING_SKETCH_PATH")) sketchDir = std::string(sp) + "/";
std::ifstream f(path);
if (!f) f.open(sketchDir + path);
if (!f) f.open(sketchDir + "data/" + path);
std::string line;
while (std::getline(f, line)) lines.push_back(line);
return lines;
}