Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: base/cpp101/hello_world.cc

Issue 23455025: Example solution for C++ 101 Exercise 1 (command-line arguments) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/cpp101/hello_world.cc
diff --git a/base/cpp101/hello_world.cc b/base/cpp101/hello_world.cc
index eb0940ef582d0c901af358a632e65dd3eca7f348..771a7ec27ca2ac756d9e3cc82967f1f3dcdb1e15 100644
--- a/base/cpp101/hello_world.cc
+++ b/base/cpp101/hello_world.cc
@@ -4,10 +4,23 @@
#include <stdio.h>
+#include <string>
+
+#include "base/command_line.h"
#include "base/logging.h"
int main(int argc, char* argv[]) {
- CHECK_GT(puts("Hello, world!"), 0);
- LOG(INFO) << "Hello, logging!";
+ CHECK(CommandLine::Init(argc, argv));
+
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ std::string greeting = command_line.GetSwitchValueASCII("greeting");
+ if (greeting.empty())
+ greeting = "Hello";
+ std::string name = command_line.GetSwitchValueASCII("name");
+ if (name.empty())
+ name = "world";
+
+ CHECK_GT(printf("%s, %s!\n", greeting.c_str(), name.c_str()), 0);
+ LOG(INFO) << greeting << ", " << name << "!";
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698