Created
May 5, 2015 18:18
-
-
Save mpapierski/0daa6f86ed97922b804d to your computer and use it in GitHub Desktop.
readlines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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