чтение / запись в тот же файл (получение gmon.out)

#c #file-io

#c #file-io

Вопрос:

Моя домашняя работа требует, чтобы я использовал один файл для вывода данных, отправки вычислений в этот файл и чтения результатов из этого файла. Данные представляют собой последовательность входных значений от 1-100, управляемых счетчиком уменьшения, основанным на переменной cin пользователем: totals .

Проблема, с которой я сталкиваюсь, заключается в том, что файл не создается как variable.txt это gm.out.

я просмотрел кучу руководств, пытался самостоятельно устранить неполадки, пытался использовать fstream / ofstream / ifstream и т. Д… Я не могу понять это. Как я могу заставить его сначала записывать данные в файл, а затем читать ИЗ этого файла?

Ошибка, которую я в основном получаю, это:

 data>>age; 
No match for 'operator>>'.
 

И

 132 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-        mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setbase)
 

^^ это происходит из-за того, что я думаю, пытается использовать ofstream с
ios::in.

Я не уверен, как выполнить эту задачу.

 #include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <fstream>

using namespace std;
int totalAges;
int age;
string str_fileIn;
int average = 0;


cout<<"Enter a filename.n";
cin>>str_fileIn;

ofstream data;
data.open //this may be the problem but i'm not sure why exactly.
    ((str_fileIn ".txt").c_str(), ios::in | ios::out);

counter = totalAges;

for (counter; counter>=1; --counter)
{
    cout<<"Enter an age value 1-100. ";

    cin>>age;
average = average   age;
}

average = average /totalAges;
highest = age;
lowest = age;

  while(data.is_open())
   { 
   if (age > highest)
      {highest = age;}

   if (age < lowest)
      {lowest = age;}
data>>age;  //this operator will not work here!
counter  ;

if (counter==totalAges)
   data.close();
}
 

Извините, если я пропустил что-то важное, я попытался включить как можно больше информации, не будучи учебником.

Спасибо.

Список ошибок:

  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp   In function 'int main()':

 104    6   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Error] no match for 'operator>>' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'int')

104 6   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] candidates are:

53  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  string  In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /string

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitslocale_classes.h                    from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /bits/locale_classes.h

41      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsios_base.h                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /bits/ios_base.h

42      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  ios                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /ios

38      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  ostream                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /ostream

39      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

996 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsbasic_string.tcc   [Note] template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::basic_string<_CharT, _Traits, _Alloc>amp;)

996 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsbasic_string.tcc   [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

879 0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /istream

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

955 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, _CharT2*)
 

955 5 C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec bitsistream.tcc [Note] template argument deduction/substitution failed:

 104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

879 0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /istream

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

923 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, _CharTamp;)

923 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

 22     D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

727 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, unsigned charamp;)

727 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

732 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, signed charamp;)

732 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

774 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, unsigned char*)

774 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

779 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, signed char*)

779 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

71  5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Resetiosflags)

71  5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

101 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setiosflags)

101 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

132 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setbase)

132 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

170 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setfill<_CharT>)

170 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

200 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setprecision)
 

200 5 C:Program Files (x86)Dev-Cpp MinGW64 lib gcc x86_64-w64-mingw324.9.2include c iomanip [Примечание] ошибка вычета / замены аргумента шаблона:

 104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

230 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setw)

230 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

104 8   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

122 9   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Error] no match for 'operator>>' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'int')

122 9   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] candidates are:

53  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  string  In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /string

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitslocale_classes.h                    from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /bits/locale_classes.h

41      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsios_base.h                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /bits/ios_base.h

42      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  ios                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /ios

38      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  ostream                  from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /ostream

39      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

 996    5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsbasic_string.tcc   [Note] template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::basic_string<_CharT, _Traits, _Alloc>amp;)

996 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsbasic_string.tcc   [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

879 0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /istream

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

955 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, _CharT2*)

955 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template argument deduction/substitution failed:

 122    11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

879 0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /istream

40      C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream                     from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

923 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, _CharTamp;)

923 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  bitsistream.tcc    [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

727 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, unsigned charamp;)

727 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

 22     D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

 732    5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, signed charamp;)

732 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

774 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, unsigned char*)

774 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

40  0   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iostream    In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c  /iostream

22      D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp                     from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

779 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template<class _Traits> std::basic_istream<char, _Traits>amp; std::operator>>(std::basic_istream<char, _Traits>amp;, signed char*)

779 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  istream [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

71  5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Resetiosflags)

71  5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

101 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setiosflags)

101 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

132 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setbase)

132 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

23  0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

170 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setfill<_CharT>)

170 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-  mingw324.9.2includec  iomanip   [Note] template argument deduction/substitution failed:
 

122 11 D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp [Примечание] ‘std::ofstream {он же std::basic_ofstream}’ не является производным от ‘std::basic_istream<_CharT, _Traits>’

  23 0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

  200   5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setprecision)

   200  5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:

122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'

 23 0   D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    In file included from D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp

230 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>amp; std::operator>>(std::basic_istream<_CharT, _Traits>amp;, std::_Setw)

230 5   C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec  iomanip [Note] template argument deduction/substitution failed:


122 11  D:Fall16_CIT133HW5COPY5001198106L_Chisholm_HW5_Q3.cpp    [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'
 

правка 1: добавлен #include — и список ошибок компилятора

Комментарии:

1. Где ваши #include s?

2. Пожалуйста, отредактируйте свой вопрос, чтобы включить дамп копирования-вставки полного вывода из компилятора, полностью и без редактирования. И включите возможные информационные примечания.

3. если вы хотите открыть файл, вы используете <fcntl.h> и вызываете fd = open(«аргументы») , затем считываете (fd, «аргументы») и записываете (fd, «аргументы) для ввода-вывода. gdsw.at/languages/c/programming-bbrown/c_075.htm

4. Используйте fstream вместо ofstram

5. Итак, я изменил данные на fstream, который он запускает, но файл по-прежнему является gmon.out Я убедился, что первое, что я сделал, это открыл файл. Должен ли я по-прежнему использовать <fcntl.h> и вызывать fd = open («аргументы») ?

Ответ №1:

Когда вы делаете

 data>>age;
 

вы пытаетесь выполнить чтение из выходного потока. Вместо этого вы должны использовать << для записи:

 data<<age;
 

Однако перед этим вам нужно проверить, действительно ли файл открыт, или любая запись в него не будет работать. Вам также необходимо убедиться, что файл создан там, где вы думаете, что он создан. Это может быть не там, где вы ожидаете, поэтому найдите его.

Ответ №2:

gmon.out Файл является результатом gprof работы инструмента профилирования среды выполнения. Вы должны включить gprof профилирование в настройках компиляции. Это не имеет никакого отношения к вашему выходному файлу.

Ваш выходной файл создается, если он вообще создается, в каталоге, из которого выполняется ваш исполняемый файл. Это не обязательно тот же каталог, в котором находятся ваши исходные файлы, или каталог, в котором создается исполняемый файл. Проверьте настройки вашего компилятора, чтобы определить, из какого каталога запускается ваш исполняемый файл, и вы должны найти variable.txt там свой файл.

Комментарии:

1. ошибка компилятора генерируется, потому ofstream что не имеет operator>> .