How do I read from an inFile using Visual C++? I am used to using inFile << intNum;
But this will not work with this compiler...
The only thing I know how to get is a char with inFile.get(char)
This is a discussion on Using Visual C++; how to read from an infile? within the C++ Programming forums, part of the General Programming Boards category; How do I read from an inFile using Visual C++? I am used to using inFile << intNum; But this ...
How do I read from an inFile using Visual C++? I am used to using inFile << intNum;
But this will not work with this compiler...
The only thing I know how to get is a char with inFile.get(char)
Funny -- I do it all the time with that compiler. Post your code and I'll guarentee that YOU made the mistake, not the compiler.
inFile << intNum <<< wrong (this is output stream)
inFile >> intNum <<< right
Last edited by Ancient Dragon; 09-27-2005 at 08:23 AM.
Yeah, your right, oh well, now I got another error. YEAH!![]()
Now i'm getting:
: error C2475: 'std::basic_istream<_Elem,_Traits>::get' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
and:
: error C2297: '>>' : illegal, right operand has type 'int [100]'
here is my code:
any ideas?Code:[red]Binary.h[/red] #include<iostream> #include<fstream> using namespace std; class BinaryFile { public: void readFromFile(ifstream& inFile, BinaryFile rd); void instertBinary(BinaryFile rd); void validRead(BinaryFile rd); void writeBinary(BinaryFile rd, ofstream& outFile); int acctNum[100]; float acctBalance; }; [red]binary.cxx[/red] #include "Binary.h" void BinaryFile::readFromFile(ifstream& inFile, BinaryFile rd) { int holder; holder = inFile.peek(); // if (holder = -1) // continue; // else inFile.get >> acctNum >> acctBalance; } void BinaryFile::writeBinary(BinaryFile rd, ofstream& outFile) { outFile.seekp(rd.acctNum % 97); outFile.write((char*)&rd); } [red]runBinary.cxx[/red] #include "Binary.h" int main() { ifstream inFile; // ofstream outFile; inFile.open("in.txt"); // outFile.open("out.txt"); ofstream outFile("binrecords.bin"); BinaryFile blankRd; for (int i = 1; i <= 100; i++) { outFile.write((char*)&blankRd, sizeof(blankRd)); } BinaryFile rd; rd.readFromFile(inFile,rd); }
sorry, figured out my stupidity![]()
We all make mistakesOriginally Posted by advocation
![]()