-
496 votesanswersviews
使用C中的ifstream逐行读取文件
file.txt的内容是: 5 3 6 4 7 1 10 5 11 6 12 3 12 4 其中 5 3 是坐标对 . 如何在C中逐行处理此数据? 我能够得到第一行,但是如何获得文件的下一行? ifstream myfile; myfile.open ("text.txt"); -
0 votesanswersviews
尝试将file.read()转换为新变量时,程序停止工作
好的,所以我有这个代码我只想将我的结构写入文件,然后使用另一个变量读取,因为我想在读取时返回userRankings的向量 . 这是我的写/读 void IOManager::WriteBin(const string &filename, userRank u1) { ofstream fsalida(filename, ios::out | ios::binary); //o... -
0 votesanswersviews
逐行读取std :: ofstream(但不是从文件中读取)
在我的项目中,我需要使用以下库(OMPL) . 我特别感兴趣的是成员函数printAsMatrix(std :: ofstream&out),它将数据输出到终端或文件 . 这里function: void ompl::geometric::PathGeometric::printAsMatrix(std::ostream &out) const { const base::State... -
1 votesanswersviews
当流程超出范围时偶尔会出现SEG FAULT
当std :: ofstream超出范围时,我很少遇到seg错误问题 . 我的Logger.h中有以下结构: struct LogRequest { std::string line; std::string prefix; }; struct FileInfo { ... -
-1 votesanswersviews
重载<<以输出到文件中
所以我有: 在我的.h: friend std::ofstream & operator <<(std::ofstream & output, myClass & s); 在我的.cpp std::ofstream & operator <<(std::ofstream & output, myClass & s) { ... -
-1 votesanswersviews
C ofstream没有创建文件[暂停]
我在类中有一个函数如下 . template <typename T> void record(std::string fname, T d) { std::cout << fname << std::endl; std::ofstream file(fname); file << d << std::endl; ... -
3 votesanswersviews
用fstream读取和写入c中的二进制文件
我正在尝试编写简单的c代码来读写文件 . 问题是我的输出文件小于原始文件,我找不到原因 . 我有一个6.6 kb的图像,我的输出图像大约6.4 kb #include <iostream> #include <fstream> using namespace std; ofstream myOutpue; ifstream mySource; int main() {... -
4 votesanswersviews
读/写PPM图像文件C.
尝试以我知道的方式读取和写入PPM图像文件(.ppm): std::istream& operator >>(std::istream &inputStream, PPMObject &other) { inputStream.seekg(0, ios::end); int size = inputStream.tellg(); inpu... -
4 votesanswersviews
读/写PPM图像文件C.
尝试以我知道的方式读取和写入PPM图像文件(.ppm): std::istream& operator >>(std::istream &inputStream, PPMObject &other) { inputStream.seekg(0, ios::end); int size = inputStream.tellg(); inpu... -
3 votesanswersviews
C - 如何让多个线程写入文件
我目前正在编写一个程序,它使用线程将字符串写入文件 . 我使用ofstream来编写这些字符串,我注意到只有一个线程可以访问该文件 . 所以我的问题:有没有办法在不同的线程中使用ofstream写入同一个文件? 如果有可能,任何例子都会很棒 . 如果没有,请告诉我,以及解决这个问题的一些方法会很棒 . 我查看了以下链接,除了它对我没有意义:Can multiple threads write in... -
0 votesanswersviews
C ofstream不会将预期的数字写入文件
美好的一天,我正在研究一个程序,它读取一个二进制文件(读取的函数给出并工作),然后将修改后的信息写回另一个二进制文件 . (我正在两种格式之间进行切换 . )如果我使用std :: cout将数字发送到控制台之前(或之后),我会使用ofstream将它们写入文件中 . 我得出了我预期的数字,但是如果我知道通过<<或写入将它们输入到流中,然后查看文件的内容 . (从这种格式到原始格式... -
1 votesanswersviews
QT ofstream使用变量作为路径名
我正在尝试创建一个需要QString和int的函数 . 将QString变量转换为ofstream的文件名,然后取整数并将其放入文件中 . 到目前为止,我已设法获取一个常量文件名,如“Filename.dat”,并将变量写入其中 . 但是当我尝试使用QString时: void write(const char what,int a){ std::ofstream writefile; ...