Skip to content

Instantly share code, notes, and snippets.

@farnoy
Created March 10, 2012 13:05
Show Gist options
  • Select an option

  • Save farnoy/2011359 to your computer and use it in GitHub Desktop.

Select an option

Save farnoy/2011359 to your computer and use it in GitHub Desktop.
Print first n lines from a file
void MainWindow::show_message()
{
std::stringstream title, content;
title << "The first [" << m_spin_button.get_value_as_int() << "] lines";
Gtk::MessageDialog dialog(title.str());
std::ifstream file;
file.open(m_file_chooser_button.get_filename().c_str(), std::ifstream::in);
char buffer[512];
short i = 0;
content << "Are: " << std::endl;
while (i < m_spin_button.get_value_as_int() ) {
file.getline(buffer, 512);
content << "[" << buffer << "]" << std::endl;
i += 1;
}
dialog.set_secondary_text(content.str());
dialog.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment