首页 > 其他 > 详细

一些技巧

时间:2015-12-21 20:03:10      阅读:230      评论:0      收藏:0      [点我收藏+]

1.直接在控制台输入 名字 或者 名字.exe即可运行程序

2.在运行程序的时候可以使用输入输出重定向 方便调试时不用重复输入数据
比如: add.exe <./data/in.txt >./data/out.txt
3.可以使用stdexcept库自定义try catch错误信息
  1. #include<iostream>// std::cout
  2. #include<thread>// std::thread
  3. #include<mutex>// std::mutex, std::lock_guard
  4. #include<stdexcept>// std::logic_error
  5. std::mutex mtx;
  6. void print_even(int x){
  7. if(x %2==0) std::cout << x <<" is even"<< std::endl;
  8. elsethrow(std::logic_error("not even"));
  9. }
  10. void print_thread_id(int id){
  11. try{
  12. // using a local lock_guard to lock mtx guarantees unlocking on destruction / exception:
  13. std::lock_guard<std::mutex> lck(mtx);
  14. print_even(id);
  15. }
  16. catch(std::logic_error&e){
  17. std::cout <<"[exception caught]"<< e.what()<< std::endl;
  18. }
  19. }
  20. int main()
  21. {
  22. std::thread threads[10];
  23. // spawn 10 threads:
  24. for(int i =0; i <10;++i)
  25. threads[i]= std::thread(print_thread_id, i +1);
  26. for(auto& th : threads) th.join();
  27. std::cin.get();
  28. return0;
  29. }
 





一些技巧

原文:http://www.cnblogs.com/gzxfd/p/5064565.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!