File: getline.cc

package info (click to toggle)
gtkmm-documentation 3.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 21,572 kB
  • sloc: cpp: 14,508; sh: 1,249; makefile: 1,042; xml: 104; perl: 64
file content (43 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*******************************************************************************
 *  Copyright (c) 2007 Jonathon Jongsma
 *
 *  This file is part of gtkmm
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>
 *
 *******************************************************************************/
#include <giomm.h>
#include <iostream>
#include <iomanip>
#include <string>

/* This is just a simple example to show you how to read a line of text at a
 * time, similar to using std::istream::getline()
 */
int main(int /* argc */, char** /* argv */)
{
  Gio::init();
  auto f = Gio::File::create_for_path("/etc/profile");
  auto file_stream = f->read();
  auto data_stream = Gio::DataInputStream::create(file_stream);

  std::string line;
  int line_num = 1;
  while (data_stream->read_line(line))
  {
    // print each line out prefixed with the line number
    std::cout << std::setw (5) << line_num++ << ": >" << line << std::endl;
  }
  return 0;
}