Skip to content

Instantly share code, notes, and snippets.

@johnbartholomew
Last active December 17, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbartholomew/5555746 to your computer and use it in GitHub Desktop.
Save johnbartholomew/5555746 to your computer and use it in GitHub Desktop.
// build with: g++ -std=c++98 -Wall -ocheck test.cpp
#include <iostream>
#include <string>
#include <sstream>
int parse_int(const char *x) {
std::istringstream ss(x);
int y;
ss >> y;
return y;
}
int main(int argc, char **argv) {
if (argc < 2) {
return 1;
}
const char *one = "one";
int x = parse_int(argv[1]);
std::ostringstream ss;
ss << x;
std::cout << "Result: " << (x == 1 ? one : ss.str()) << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment