File and String Input and Output StreamsFiles, respectively strings, can be used in the same way as C++-streams with the data types file_istream, file_ostream, string_istream, and string_ostream. In particular, the operators << and >> can be used. Remark: The data type file_istream is equivalent to the ifstream type of C++ and file_ostream is equivalent to ofstream. ExampleThe following example shows how a string_istream can be used in a program. The data types file_ostream, string_istream, and string_ostream can be used similarly.#include <LEDA/system/stream.h> int main() { leda::string s="17 18 19 20 21 22 23 24 25 26"; leda::string_istream input(s); //defines the string_istream input //and connects it to the string s int num; while (!input.eof()) { //while not end of input is reached input >> num; //extract next number from input std::cout << num << std::endl; } return 0; } |
See also:Manual Entries: |