Skip to content

Commit 8e93026

Browse files
authored
Merge pull request #82 from codecrafters-io/CC-1237
CC-1237: Use autoflush using std::unitbuf for c++ repos
2 parents 2fd9654 + 95ac57d commit 8e93026

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

compiled_starters/cpp/src/Server.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <fstream>
44

55
int main(int argc, char* argv[]) {
6+
// Flush after every std::cout / std::cerr
7+
std::cout << std::unitbuf;
8+
std::cerr << std::unitbuf;
9+
610
// You can use print statements as follows for debugging, they'll be visible when running tests.
711
std::cout << "Logs from your program will appear here" << std::endl;
812

solutions/cpp/01-dr6/code/src/Server.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <fstream>
44

55
int main(int argc, char* argv[]) {
6+
// Flush after every std::cout / std::cerr
7+
std::cout << std::unitbuf;
8+
std::cerr << std::unitbuf;
9+
610
if (argc != 3) {
711
std::cerr << "Expected two arguments" << std::endl;
812
return 1;

solutions/cpp/01-dr6/diff/src/Server.cpp.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
@@ -1,36 +1,32 @@
1+
@@ -1,40 +1,36 @@
22
#include <cstring>
33
#include <iostream>
44
#include <fstream>
55

66
int main(int argc, char* argv[]) {
7+
// Flush after every std::cout / std::cerr
8+
std::cout << std::unitbuf;
9+
std::cerr << std::unitbuf;
10+
711
- // You can use print statements as follows for debugging, they'll be visible when running tests.
812
- std::cout << "Logs from your program will appear here" << std::endl;
913
-

starter_templates/cpp/src/Server.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <fstream>
44

55
int main(int argc, char* argv[]) {
6+
// Flush after every std::cout / std::cerr
7+
std::cout << std::unitbuf;
8+
std::cerr << std::unitbuf;
9+
610
// You can use print statements as follows for debugging, they'll be visible when running tests.
711
std::cout << "Logs from your program will appear here" << std::endl;
812

0 commit comments

Comments
 (0)