Skip to content

Instantly share code, notes, and snippets.

@mpapierski
Created May 5, 2015 18:18
Show Gist options
  • Save mpapierski/0daa6f86ed97922b804d to your computer and use it in GitHub Desktop.
Save mpapierski/0daa6f86ed97922b804d to your computer and use it in GitHub Desktop.
readlines
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <array>
int
main()
{
std::ifstream ifs("/etc/passwd");
std::string line;
while (std::getline(ifs, line))
{
std::stringstream ss(line);
std::array<std::string, 3> tokens;
for (auto & el : tokens)
{
std::getline(ss, el, ':');
}
if (!tokens[2].empty() && std::stoi(tokens[2]) > 500)
{
std::cout << tokens[0] << "/uid " << tokens[2] << std::endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment