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; |
} |