我的作业要求我使用单个文件输出数据,将计算结果发送到该文件,然后从该文件中读取结果。 数据是一系列从1-100开始的输入年龄,由用户根据变量cin的减量计数器控制:totalAges。
我遇到的问题是文件没有被创建为variable.txt 它是gmon.out。
我看过一堆试图对自己进行故障排除的教程,尝试使用fstream / ofstream / ifstream等...我无法弄明白。如何让它首先将数据写入文件,然后从该文件中读取?
我主要得到的错误是:
data>>age;
No match for 'operator>>'.
和
132 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64- mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)
^^发生了一堆我正在考虑尝试使用ofstream的 IOS ::英寸
我不确定如何完成这项任务。
#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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In function 'int main()':
104 6 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp [Note] candidates are:
53 0 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\locale_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\ios_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
955 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
955 5 C:\ Program Files(x86)\ Dev-Cpp \ MinGW64 \ lib \ gcc \ x86_64-w64-mingw32 \ 4.9.2 \ include \ c ++ \ bits \ istream.tcc [注意]模板参数扣除/替换失败:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
923 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&)
923 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
727 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)
727 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
732 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)
732 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
774 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*)
774 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
779 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*)
779 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
71 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Resetiosflags)
71 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
101 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setiosflags)
101 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
132 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)
132 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
170 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setfill<_CharT>)
170 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
200 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setprecision)
200 5 C:\ Program Files(x86)\ Dev-Cpp \ MinGW64 \ lib \ gcc \ x86_64-w64-mingw32 \ 4.9.2 \ include \ c ++ \ iomanip [注意]模板参数扣除/替换失败:< / p>
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
230 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw)
230 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
104 8 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp [Note] candidates are:
53 0 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\locale_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\ios_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
955 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
955 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
22 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
923 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&)
923 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\istream.tcc [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
727 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)
727 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
732 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)
732 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
774 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*)
774 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
779 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*)
779 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\istream [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
71 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Resetiosflags)
71 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
101 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setiosflags)
101 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
132 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)
132 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
170 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setfill<_CharT>)
170 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64- mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\ Fall16_CIT133 \ HW5 \ COPY5001198106L_Chisholm_HW5_Q3.cpp [注意]&#39; std :: ofstream {aka std :: basic_ofstream}&#39;不是源于&#39; std :: basic_istream&lt; _CharT,_Traits&gt;&#39;
23 0 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
200 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setprecision)
200 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_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_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp In file included from D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp
230 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw)
230 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iomanip [Note] template argument deduction/substitution failed:
122 11 D:\Fall16_CIT133\HW5\COPY5001198106L_Chisholm_HW5_Q3.cpp [Note] 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'
编辑1:添加了#include - 和编译器错误列表
答案 0 :(得分:2)
当你这样做时
data>>age;
您正试图从输出流中读取。您应该使用<<
来代替:
data<<age;
在此之前,您需要检查文件是否实际打开,或者对它的任何写入都不起作用。您还需要确保在认为创建文件的位置创建文件。它可能不在您期望的位置,因此请搜索它。
答案 1 :(得分:-1)
gmon.out
文件是output from the gprof
runtime profiling tool。您必须在编译设置中启用gprof
分析。它与您的输出文件无关。
正在创建输出文件(如果它完全被创建),在可执行文件执行的目录中。这与源文件不一定是相同的目录,或者是创建可执行文件的目录。检查编译器设置以确定可执行文件的目录,并在那里找到variable.txt
文件。