Debian Codegraph @

examples/book/giomm/getline/getline.cc

raw
1 /*******************************************************************************
2 * Copyright (c) 2007 Jonathon Jongsma
3 *
4 * This file is part of gtkmm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>
18 *
19 *******************************************************************************/
20 #include <giomm.h>
21 #include <iostream>
22 #include <iomanip>
23 #include <string>
24
25 /* This is just a simple example to show you how to read a line of text at a
26 * time, similar to using std::istream::getline()
27 */
28 int main(int /* argc */, char** /* argv */)
29 {
30 Gio::init();
31 auto f = Gio::File::create_for_path("/etc/profile");
32 auto file_stream = f->read();
33 auto data_stream = Gio::DataInputStream::create(file_stream);
34
35 std::string line;
36 int line_num = 1;
37 while (data_stream->read_line(line))
38 {
39 // print each line out prefixed with the line number
40 std::cout << std::setw (5) << line_num++ << ": >" << line << std::endl;
41 }
42 return 0;
43 }