Could someone show me what I am doing wrong to read a data file? I was told that the charaters that was comeing from the file did not need to be declared. Is this true? I understand that you have to open and close the filesI just can't figure it out. You don't have to do the code just tell me what I need to do. Thanks in advance.
#include <fstream>
using namespace std;
int main()
{
//Declare string varibles
//Open the files
fin.open("inInfo.txt");
fout.open("outInfo.txt", ios::app);
if (!inIfo.txt)
//Initialize dint ch;
int ch1;
int sum;
//Get data from inInfo.txt
fin >> ch;
fin >> test2;
fin >> test3;
//mathmatical funtions
sum = test2 + test3;
fout << "The sum of"<< test2 << " and " << test3 <<"is" << sum;
fout << endl;
sum = test2 * test3;
fout << "The product of"<< test2 <<" and " << test3 <<" = " << sum;
fout << endl;
1>------ Build started: Project: week3carper, Configuration: Debug Win32 ------
1>Compiling...
1>week3carper.cpp
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(22) : error C2065: 'fin' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(22) : error C2228: left of '.open' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(23) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(23) : error C2228: left of '.open' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(24) : error C2065: 'inIfo' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(24) : error C2228: left of '.txt' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(31) : error C2065: 'fin' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(31) : error C2065: 'ch' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(32) : error C2065: 'fin' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(32) : error C2065: 'test2' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(33) : error C2065: 'fin' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(33) : error C2065: 'test3' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(39) : error C2065: 'test2' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(39) : error C2065: 'test3' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(40) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(40) : error C2065: 'test2' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(40) : error C2065: 'test3' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(41) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(41) : error C2563: mismatch in formal parameter list
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(41) : error C2568: '<<' : unable to resolve function overload
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(42) : error C2065: 'test2' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(42) : error C2065: 'test3' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(43) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(43) : error C2065: 'test2' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(43) : error C2065: 'test3' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(44) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(44) : error C2563: mismatch in formal parameter list
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(44) : error C2568: '<<' : unable to resolve function overload
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(49) : error C2065: 'fin' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(49) : error C2228: left of '.close' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(50) : error C2065: 'fout' : undeclared identifier
1>c:\documents and settings\hp_administrator\my documents\visual studio 2008\week3carper\week3carper\week3carper.cpp(50) : error C2228: left of '.close' must have class/struct/union
1> type is ''unknown-type''
1>Build log was saved at "file://c:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2008\week3carper\week3carper\Debug\BuildLog.htm"
1>week3carper - 32 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========