THRIFT-2691 - C++ tutorial: printfs removed, generated operator<< used
diff --git a/tutorial/cpp/CppServer.cpp b/tutorial/cpp/CppServer.cpp
index d75b553..653caaa 100644
--- a/tutorial/cpp/CppServer.cpp
+++ b/tutorial/cpp/CppServer.cpp
@@ -25,6 +25,7 @@
#include <thrift/server/TThreadedServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TTransportUtils.h>
+#include <thrift/TToString.h>
#include <iostream>
#include <stdexcept>
@@ -46,16 +47,16 @@
CalculatorHandler() {}
void ping() {
- printf("ping()\n");
+ cout << "ping()" << endl;
}
int32_t add(const int32_t n1, const int32_t n2) {
- printf("add(%d,%d)\n", n1, n2);
+ cout << "add(" << n1 << ", " << n2 << ")" << endl;
return n1 + n2;
}
- int32_t calculate(const int32_t logid, const Work &work) {
- printf("calculate(%d,{%d,%d,%d})\n", logid, work.op, work.num1, work.num2);
+ int32_t calculate(const int32_t logid, const Work& work) {
+ cout << "calculate(" << logid << ", " << work << ")" << endl;
int32_t val;
switch (work.op) {
@@ -86,9 +87,7 @@
SharedStruct ss;
ss.key = logid;
- char buffer[12];
- snprintf(buffer, sizeof(buffer), "%d", val);
- ss.value = buffer;
+ ss.value = to_string(val);
log[logid] = ss;
@@ -96,12 +95,12 @@
}
void getStruct(SharedStruct &ret, const int32_t logid) {
- printf("getStruct(%d)\n", logid);
+ cout << "getStruct(" << logid << ")" << endl;
ret = log[logid];
}
void zip() {
- printf("zip()\n");
+ cout << "zip()" << endl;
}
protected:
@@ -145,8 +144,8 @@
*/
- printf("Starting the server...\n");
+ cout << "Starting the server..." << endl;
server.serve();
- printf("done.\n");
+ cout << "Done." << endl;
return 0;
}