loadStrings()

Input / Files

Description

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

NameTypeDescription
pathstd::stringpath to the file

Returns

std::vector

Related

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; }