Algorithmic Solutions > LEDA > LEDA Guide > Simple, Basic, and Advanced Data Types > Simple Data Types > File and String Streams

File and String Input and Output Streams

Files, 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.

Example

The 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:

Strings


Manual Entries:

File Input Streams

File Output Streams

String Input Streams

String Output Streams




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH