在大學時我的基本的Linux程序設計過程中,我們使用fcntl.h unistd.h中和使用 C++字符串,我得到如下:C++字符串中讀取功能從fcntl.h
statusOfFunction = write(fileDescriptor, input.c_str(), input.length());
這條線工作。我得到一個創建的文件,其中包含輸入字符串的內容。但是,爲什麼沒有任何這些行的工作:
statusOfFunction = read(fileDescriptor, reading.c_str(), 10);
Error: No matching function call to "read"
statusOfFunction = read(fileDescriptor, reading, 10);
Error: No matching function call to "read"
statusOfFunction = read(fileDescriptor, &reading, 10);
No error throws up, but does not get executed
statusOfFunction = read(fileDescriptor, &reading.c_str(), 10);
Error: No matching function call to "read"
https://www.dropbox.com/s/lnw208uo3xurqxf/Basic%20Unix%20Operations%20on%20Text%20Files.cpp?dl=0
這裏是程序,供大家參考。 謝謝! :)
什麼是「閱讀」?你需要將原型與'read'匹配,根據'man 2 read',它是'ssize_t read'(int fd,void * buf,size_t count);'所以你需要讀取一個void指針到足夠大的緩衝區保存10個字節(或者你的「count」)。 – PSkocik 2014-09-23 08:51:46
在您的基本Linux編程課程中,他們還沒有涵蓋'const'的含義? – WhozCraig 2014-09-23 08:56:46