Monthly Archives: April 2018

std::getline

std::getline時會等待斷行符,但需要注意的是 在使用pipe redirect時,會有flush的問題 boost::process::ipstream child_stdout; boost::process::opstream child_stdin; boost::process::child child_process; child_process = boost::process::child(exe_path, boost::process::std_out > child_stdout, boost::process::std_err > child_stdout, boost::process::std_in < child_stdin); //... child_stdin

Posted in Tips | Leave a comment

comment tips

多行註解時 有時候只是暫時不需要 /* int x; // blah blah */ 要取消掉,最簡單的方式是直接加上// ///* int x; // blah blah //*/ 這樣可以方便以後加回來,因為如果是直接刪掉/*, */ 加回來時常常會忘記要在哪裡開始結束當然 #if 0, #if 1這樣也是一種常見的方式 或是 if(0) {}

Posted in Tips | Leave a comment

genisoimage

genisoimage -joliet-long -J -r -allow-lowercase -allow-multidot -o 檔案名.iso 目錄名稱 -J 為必須, 指定input charset 為unicode, 不然default是iso8859-1, 會導致output的名稱被取代成underscore

Posted in System Administration | Leave a comment

header only files tips

當開發header only library時,有時候會需要static or global物件,但因為C++ ODR的原因, 當物件被重複定義時在link階段會報錯。 例如 //X.h class X { public: static int m; //這只是declaration }; //main.cpp #include “X.h” int main() { X a; a.m = 0; return 0; } /tmp/ccaFpbvF.o: In function `main’: t.cc:(.text+0x6): undefined reference to … Continue reading

Posted in C++ Language | Leave a comment