#include <stdio.h>
#include<iostream>
#include <thread>
#include<mutex>
#include <string>
#include <fstream>
using namespace std;
class LofFile
{
public:
LofFile() {
f.oepn("log.txt");
}
void shared_print(string id, int value)
{
lock_guard<mutex>locker(m_mutex);
f << "from" << id << ":" << value << endl;
}
private:
mutex m_mutex;
std::ofstream f;
};
void function_1(LofFile&log) {
for (int i = 0; i > -100; i--)
log.shared_print("from ti:", i);
}
int main() {
LofFile log;
thread t1(function_1, ref(log));
for (int i = 0; i < 100; i++)
log.shared_print("from main", i);
t1.join();
}
1>------ 已啟動全部重新生成: 專案: multithread, 配置: Debug Win32 ------
1> main.cpp
1>c:\users\will\documents\visual studio 2015\projects\multithread\multithread\main.cpp(14): error C2039: “oepn”: 不是“std::basic_ofstream<char,std::char_traits<char>>”的成員
========== 全部重新生成: 成功 0 個,失敗 1 個,跳過 0 個 ==========
uj5u.com熱心網友回復:
這不是很明顯呢?是open,不是oepnuj5u.com熱心網友回復:
uj5u.com熱心網友回復:
關于自己是否適合編程的很簡單的測驗:在報紙或雜志上隨便找一段約1000字的文章,在Word中輸入一遍。輸完后再參考下面答案:
A里面有10處以上文字或標點錯誤
B里面沒有文字或標點錯誤并敢為此跟人打賭
C里面沒有文字或標點錯誤并且字體和排版完全與原稿一致
D列印在半透明的紙上和原稿重疊在一起檢查一模一樣,且自我感覺很有成就感
A不適合編程(理由:打字準確度偏低、粗心大意)
B初級程式員(理由:打字準確度很高、認真細致、自信、理解全角半角概念)
C高級程式員(理由:在B的基礎上理解字體和排版也是電腦列印的重要因素、但相比D還不夠偏執、精益求精、結果可驗證)
D軟體專案經理(理由:能針對專案給出令人信服的細致到極點的需求說明和典型測驗用例。用戶幾乎挑不出毛病。專業!)
如果想從A變成B的話,到我的資源http://download.csdn.net/detail/zhao4zhong1/4084259里面下載“適合程式員的鍵盤練習”
uj5u.com熱心網友回復:
please oepn your eyes轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/75400.html
標籤:進程/線程/DLL
下一篇:CMake 3.11.0 錯誤
