-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CC-1237: Use autoflush using std::unitbuf for c++ repos
- Loading branch information
Showing
5 changed files
with
167 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
bool match_pattern(const std::string& input_line, const std::string& pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} | ||
else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
bool match_pattern(const std::string &input_line, const std::string &pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
std::cout << "Logs from your program will appear here" << std::endl; | ||
int main(int argc, char *argv[]) { | ||
// Flush after every std::cout / std::cerr | ||
std::cout << std::unitbuf; | ||
std::cerr << std::unitbuf; | ||
|
||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
// You can use print statements as follows for debugging, they'll be visible | ||
// when running tests. | ||
std::cout << "Logs from your program will appear here" << std::endl; | ||
|
||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
|
||
// Uncomment this block to pass the first stage | ||
// | ||
// std::string input_line; | ||
// std::getline(std::cin, input_line); | ||
// | ||
// try { | ||
// if (match_pattern(input_line, pattern)) { | ||
// return 0; | ||
// } else { | ||
// return 1; | ||
// } | ||
// } catch (const std::runtime_error& e) { | ||
// std::cerr << e.what() << std::endl; | ||
// return 1; | ||
// } | ||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
|
||
// Uncomment this block to pass the first stage | ||
// std::string input_line; | ||
// std::getline(std::cin, input_line); | ||
// | ||
// try { | ||
// if (match_pattern(input_line, pattern)) { | ||
// return 0; | ||
// } else { | ||
// return 1; | ||
// } | ||
// } catch (const std::runtime_error& e) { | ||
// std::cerr << e.what() << std::endl; | ||
// return 1; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,45 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
bool match_pattern(const std::string& input_line, const std::string& pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} | ||
else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
bool match_pattern(const std::string &input_line, const std::string &pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::string input_line; | ||
std::getline(std::cin, input_line); | ||
|
||
try { | ||
if (match_pattern(input_line, pattern)) { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
} catch (const std::runtime_error& e) { | ||
std::cerr << e.what() << std::endl; | ||
return 1; | ||
} | ||
int main(int argc, char *argv[]) { | ||
// Flush after every std::cout / std::cerr | ||
std::cout << std::unitbuf; | ||
std::cerr << std::unitbuf; | ||
|
||
std::cout << "Logs from your program will appear here" << std::endl; | ||
|
||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::string input_line; | ||
std::getline(std::cin, input_line); | ||
|
||
try { | ||
if (match_pattern(input_line, pattern)) { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
} catch (const std::runtime_error& e) { | ||
std::cerr << e.what() << std::endl; | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,62 @@ | ||
@@ -1,45 +1,40 @@ | ||
@@ -1,48 +1,45 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
bool match_pattern(const std::string& input_line, const std::string& pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} | ||
else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
bool match_pattern(const std::string &input_line, const std::string &pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
- // You can use print statements as follows for debugging, they'll be visible when running tests. | ||
- std::cout << "Logs from your program will appear here" << std::endl; | ||
- | ||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
int main(int argc, char *argv[]) { | ||
// Flush after every std::cout / std::cerr | ||
std::cout << std::unitbuf; | ||
std::cerr << std::unitbuf; | ||
|
||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
- // You can use print statements as follows for debugging, they'll be visible | ||
- // when running tests. | ||
std::cout << "Logs from your program will appear here" << std::endl; | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
|
||
- // Uncomment this block to pass the first stage | ||
- // | ||
- // std::string input_line; | ||
- // std::getline(std::cin, input_line); | ||
- // | ||
- // try { | ||
- // if (match_pattern(input_line, pattern)) { | ||
- // return 0; | ||
- // } else { | ||
- // return 1; | ||
- // } | ||
- // } catch (const std::runtime_error& e) { | ||
- // std::cerr << e.what() << std::endl; | ||
- // return 1; | ||
- // } | ||
+ std::string input_line; | ||
+ std::getline(std::cin, input_line); | ||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
|
||
- // Uncomment this block to pass the first stage | ||
- // std::string input_line; | ||
- // std::getline(std::cin, input_line); | ||
- // | ||
- // try { | ||
- // if (match_pattern(input_line, pattern)) { | ||
- // return 0; | ||
- // } else { | ||
- // return 1; | ||
- // } | ||
- // } catch (const std::runtime_error& e) { | ||
- // std::cerr << e.what() << std::endl; | ||
- // return 1; | ||
- // } | ||
+ std::string input_line; | ||
+ std::getline(std::cin, input_line); | ||
+ | ||
+ try { | ||
+ if (match_pattern(input_line, pattern)) { | ||
+ return 0; | ||
+ } else { | ||
+ return 1; | ||
+ } | ||
+ } catch (const std::runtime_error& e) { | ||
+ std::cerr << e.what() << std::endl; | ||
+ return 1; | ||
+ } | ||
+ try { | ||
+ if (match_pattern(input_line, pattern)) { | ||
+ return 0; | ||
+ } else { | ||
+ return 1; | ||
+ } | ||
+ } catch (const std::runtime_error& e) { | ||
+ std::cerr << e.what() << std::endl; | ||
+ return 1; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
bool match_pattern(const std::string& input_line, const std::string& pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} | ||
else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
bool match_pattern(const std::string &input_line, const std::string &pattern) { | ||
if (pattern.length() == 1) { | ||
return input_line.find(pattern) != std::string::npos; | ||
} else { | ||
throw std::runtime_error("Unhandled pattern " + pattern); | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
std::cout << "Logs from your program will appear here" << std::endl; | ||
int main(int argc, char *argv[]) { | ||
// Flush after every std::cout / std::cerr | ||
std::cout << std::unitbuf; | ||
std::cerr << std::unitbuf; | ||
|
||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
// You can use print statements as follows for debugging, they'll be visible | ||
// when running tests. | ||
std::cout << "Logs from your program will appear here" << std::endl; | ||
|
||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
if (argc != 3) { | ||
std::cerr << "Expected two arguments" << std::endl; | ||
return 1; | ||
} | ||
|
||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
std::string flag = argv[1]; | ||
std::string pattern = argv[2]; | ||
|
||
// Uncomment this block to pass the first stage | ||
// | ||
// std::string input_line; | ||
// std::getline(std::cin, input_line); | ||
// | ||
// try { | ||
// if (match_pattern(input_line, pattern)) { | ||
// return 0; | ||
// } else { | ||
// return 1; | ||
// } | ||
// } catch (const std::runtime_error& e) { | ||
// std::cerr << e.what() << std::endl; | ||
// return 1; | ||
// } | ||
if (flag != "-E") { | ||
std::cerr << "Expected first argument to be '-E'" << std::endl; | ||
return 1; | ||
} | ||
|
||
// Uncomment this block to pass the first stage | ||
// std::string input_line; | ||
// std::getline(std::cin, input_line); | ||
// | ||
// try { | ||
// if (match_pattern(input_line, pattern)) { | ||
// return 0; | ||
// } else { | ||
// return 1; | ||
// } | ||
// } catch (const std::runtime_error& e) { | ||
// std::cerr << e.what() << std::endl; | ||
// return 1; | ||
// } | ||
} |