Привет, я пытаюсь выполнить некоторые операции с файлами, и при необходимости пользователь может открыть несколько файлов. Я создал производный вектор ofstream
, но когда я хочу стереть i. элемент (который файл был закрыт) с компилятором std::vector<Type>::erase(std::vector<Type>::iterator)
дает мне ошибку, но у меня есть другой вектор, полученный из 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);
}
}
Я использую Nsight Eclipse Edition 6.0 в Ubuntu 12.04, и мне все равно нужен открытый файл или файлы, ошибки из раздела «Проблема» выходных данных eclipse;
- требуется от ‘_OI std::__copy_move_a(_II, _II, _OI) [с логическим значением _IsMove = false; _II = std::basic_ofstream; _OI = std::basic_ofstream]
- требуется от ‘_OI std::__copy_move_a2(_II, _II, _OI) [с логическим значением _IsMove = false; _II = __gnu_cxx::__normal_iterator*, std::vector > >; _OI = __gnu_cxx::__normal_iterator*, std::vector > >]
- требуется от ‘_OI std::copy(_II, _II, _OI) [с _II = __gnu_cxx::__normal_iterator*, std::vector > >; _OI = __gnu_cxx::__normal_iterator*, std::vector > >]
- требуется от ‘_OI std::copy(_II, _II, _OI) [с _II = __gnu_cxx::__normal_iterator*, std::vector > >; _OI = __gnu_cxx::__normal_iterator*, std::vector > >]
- std::basic_streambuf‹_CharT, _Traits>& std::basic_streambuf‹_CharT, _Traits>::operator=(const std::basic_streambuf‹_CharT, _Traits>&) [с _CharT = char; _Traits = std::char_traits]
- std::ios_base& std::ios_base::operator=(const std::ios_base&)
- make: *** [dosya/dosya.o] Ошибка 1
- в этом содержании
- в этом содержании
- требуется отсюда
Последняя ошибка, указывающая на строку кода
Вывод компилятора: (Некоторые слова на турецком языке, dosya = файл, 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)`
Я понятия не имею об этом. Я также просмотрел это, это, это, это (речь идет об ошибке), Часто задаваемые вопросы - q7.1, this (о списке, но ошибка такая же, и я говорю, что ошибка на самом деле не ошибка, и я не менял компилятор (nvcc)). Всем спасибо.
std::ofstream
s не могут быть скопированы. Вам нужно использовать указатели. - person molbdnilo   schedule 07.11.2014std::vector
используетoperator=
для добавления или удаления? Разве это не сделано с очередью указателей или стеком и использоватьfree(void*)
после удаления элемента? Речь идет о стандартных определениях С++ 11? - person Orkun Kasapoglu   schedule 07.11.2014std::vector<std::ofstream*> of;
, и теперь ошибки нет, но я еще не пробовал. Спасибо всем еще раз. - person Orkun Kasapoglu   schedule 07.11.2014vector<unique_ptr<ostream>>
- person Neil Kirk   schedule 07.11.2014