- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您好,我正在尝试执行一些文件操作,如果需要,用户可以打开多个文件。我已经创建了一个 vector 派生的 ofstream
但是当我想删除 i.使用 std::vector<Type>::erase(std::vector<Type>::iterator)
编译器的元素(哪个文件已关闭)给我错误,但我有另一个 vector 派生的 std::string
并且我以同样的方式删除它,它没有给出错误。我的代码是;
#include <iostream>
#include <fstream>
#include <vector>
std::vector<std::ofstream> of;
std::vector<std::string> sv;
int CloseFile(int id, file_t ft) {
std::vector<std::ofstream>::iterator i;
std::vector<std::string>::iterator j;
if (of[id].is_open() == true) {
of[id].close();
i = of.begin() + id;
j = sv.begin() + id;
of.erase(i); // showing error for this line
sv.erase(j);
}
}
我在 Ubuntu 12.04 上使用 Nsight Eclipse Edition 6.0,我需要打开一个或多个文件,但 Eclipse 输出的问题部分的错误是;
最后一个错误提示代码行
编译器输出:(有些词是土耳其语,dosya = file,GeriDonus_t = Return_t,DosyaKapat = FileClose)
16:06:56 **** Incremental Build of configuration Debug for project deneme ****`
make all`
Building file: ../dosya/dosya.cpp`
Invoking: NVCC Compiler`
/usr/local/cuda-6.0/bin/nvcc -I"/usr/local/cuda-6.0/samples/3_Imaging" -I"/usr/local /cuda-6.0/samples/common/inc" -I"/opt/Calismalar/Cuda/cuda-workspace/deneme" -I/usr/local/opencv/include -I/usr/local/opencv/include/opencv -I/opt/Calismalar/Cuda/cuda-workspace/deneme/ -G -g -O0 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_32,code=sm_32 -odir "dosya" -M -o "dosya/dosya.d" "../dosya/dosya.cpp"`
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.`
/usr/local/cuda-6.0/bin/nvcc -I"/usr/local/cuda-6.0/samples/3_Imaging" -I"/usr/local/cuda-6.0/samples/common/inc" -I"/opt/Calismalar/Cuda/cuda-workspace/deneme" -I/usr/local/opencv/include -I/usr/local/opencv/include/opencv -I/opt/Calismalar/Cuda/cuda-workspace/deneme/ -G -g -O0 --compile -x c++ -o "dosya/dosya.o" "../dosya/dosya.cpp"
In file included from /usr/include/c++/4.8/ios:42:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from ../dosya/dosya.h:13,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/bits/basic_ios.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = std::basic_ofstream<char>*; _OI = std::basic_ofstream<char>*]’:
/usr/include/c++/4.8/bits/stl_algobase.h:390:70: required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = std::basic_ofstream<char>*; _OI = std::basic_ofstream<char>*]’
/usr/include/c++/4.8/bits/stl_algobase.h:428:38: required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<std::basic_ofstream<char>*, std::vector<std::basic_ofstream<char> > >; _OI = __gnu_cxx::__normal_iterator<std::basic_ofstream<char>*, std::vector<std::basic_ofstream<char> > >]’
/usr/include/c++/4.8/bits/stl_algobase.h:460:17: required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<std::basic_ofstream<char>*, std::vector<std::basic_ofstream<char> > >; _OI = __gnu_cxx::__normal_iterator<std::basic_ofstream<char>*, std::vector<std::basic_ofstream<char> > >]’
/usr/include/c++/4.8/bits/vector.tcc:138:2: required from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = std::basic_ofstream<char>; _Alloc = std::allocator<std::basic_ofstream<char> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::basic_ofstream<char>*, std::vector<std::basic_ofstream<char> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::basic_ofstream<char>*]’
../dosya/dosya.cpp:152:27: required from here
/usr/include/c++/4.8/bits/ios_base.h:789:5: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private
operator=(const ios_base&);
^
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from ../dosya/dosya.h:13,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from ../dosya/dosya.h:13,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/ostream:58:11: note: synthesized method ‘std::basic_ios<char>& std::basic_ios<char>::operator=(const std::basic_ios<char>&)’ first required here
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
^
In file included from ../dosya/dosya.h:14:0,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/fstream:599:11: note: synthesized method ‘std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&)’ first required here
class basic_ofstream : public basic_ostream<_CharT,_Traits>
^
In file included from /usr/include/c++/4.8/ios:43:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from ../dosya/dosya.h:13,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/streambuf:810:7: error: ‘std::basic_streambuf<_CharT, _Traits>& std::basic_streambuf<_CharT, _Traits>::operator=(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is private
operator=(const basic_streambuf&) { return *this; };
^
In file included from ../dosya/dosya.h:14:0,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/fstream:72:11: error: within this context
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
^
/usr/include/c++/4.8/fstream:599:11: note: synthesized method ‘std::basic_filebuf<char>& >std::basic_filebuf<char>::operator=(const std::basic_filebuf<char>&)’ first required here
class basic_ofstream : public basic_ostream<_CharT,_Traits>
^
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from ../dosya/dosya.h:13,
from ../dosya/dosya.cpp:9:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: note: synthesized method ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const std::basic_ofstream<char>&)’ first required here
*__result = *__first;
^
make: *** [dosya/dosya.o] Error 1
16:06:57 Build Finished (took 456ms)`
我对此一无所知。我也看过 this , this , this , this (它是关于 eclipse bug ), FAQ - q7.1, this (关于 List 但错误是相同的并且说错误实际上不是错误而且我没有更改编译器(nvcc )).谢谢大家。
最佳答案
Gcc-4.8 不支持移动流。在这方面,您的代码符合 C++11,只是您的实现不符合。
关于c++ - std::vector<std::ofstream>::erase 给出编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26803255/
我想在一个函数中打开一个文件,将打开的文件对象返回给 main,并在另一个函数中使用它函数来填充文件。编译器似乎告诉我,我正在尝试访问 iostream 的私有(private)成员。有没有办法做到这
我最近写了一个记录器类。编译这段代码时: std::ofstream *stream = new std::ofstream; stream->open( log_file_name.c_str()
我有以下测试代码,其中有一个参数 fS,它是 ofstream 的容器: #include #include #include #include int
我正在尝试实现一个记录器,它可以注册到多个流,如 ostringstream、ofstream 等。我试图实现这样的功能 void register_stream(std::ostream& a);
我有一个在线程上写入文件的类 class A{ public: void writeToFile(ofstream& outFile, obj &a) { //...
我有以下代码 void _log_message(const char* fmt, ...) { va_list arg; ofstream logfile; cout << "Open Lo
我刚刚开始阅读如何打开和编辑文件。使用 ifstream 时,如果文件不存在,则不会创建它。 引用下面的代码,条件 (!outfile) 何时为假,就好像文件不存在一样,构造函数将简单地创建它,因此总
#include #define LOGFATAL(msg) log(0, msg) std::ofstream *logst = NULL; void log(int sev, char *msg
我在使用 ofstream 时遇到问题一次将两个不同的输出写入两个不同的文件。程序编译运行正常,并向p1output.txt写入数据,但是当我打开p2output.txt时,除了第一行内容外是空白的:
我有一个“资源模块”类来管理我的应用程序的所有资源,它主要从一个包含所有内容的文件“RESOURCES.DAT”中读取。 从文件中请求新数据的所有对象都通过 ResourceModule,因此我可以管
我遇到流问题,程序无法打开我要写入的文件。最小完整可变代码如下: #include #include using namespace std; int main(){ string roo
我已经研究了好几个小时了,我只知道答案很简单。似乎无论我做什么我都无法打开文件。这是一个多类程序,所以在标题中我有 #include #include class A{ string path
所以我想写一个可以像这样使用的缩进输出类: Debug f; f.open("test.txt"); f }' and '') ofs #include using namespace std;
大家好... 抱歉我的英语不好,但是会说西类牙语... 这周,为了这个proyect的学习和工作,我想创建一个软件来制作文件(.us)... 示例 char name[50]; //Or string
我不想在 main() 中构造 ofstream。这是我所做的,但它没有编译: #include using namespace std; class test { private: ofs
谁能告诉我这是怎么回事? #include #include #include #include #include class writeManager { std::vector
我有一个 C++ 类,它将其数据写出到二进制 std::ofstream。该类将数据存储为 boost:shared_array 但我已经消除了这个问题。问题出在 ofstream 上对 write(
在我的程序中,我的 dataout: void outfile 没有写入文件,任何人都可以找出原因吗? using namespace std; #include #include #include
我想在文件上写点东西。但它只是没有像它必须假设的那样编写。 void main() { int accno; char name[20]; float deposit;
我遇到了一个奇怪的问题。我有两个函数,它们都有一个通过引用传递的 ofstream。但是,当我调用第二个函数时,正在打印第一个函数的一部分。 这是第一个函数: void GamePlay::dealD
我是一名优秀的程序员,十分优秀!