Can someone help me with file streams with c++? Mostly with binary types.
I'm trying to lead this up to being able to read from meshes (basically multiple sets of arrays). I'm not thinking char being the only thing to write or read helps. If anyone has experience in this, please teach me all you know.
Cool, i got it! #include <iostream> #include <fstream> using namespace std; /* int main() { int size; char buffer[] = {3, 4, 4, 12, 53, 66, 23, 6, 45, 9}; ofstream file("Test.bin", ios::out | ios::binary); size = 10; file.write(buffer, size); cout << buffer; file.close(); return 0; } */ int main() { int size; char *buffer; int sum = 0; ifstream file("Test.bin", ios::in | ios::binary | ios::ate); size = file.tellg(); file.seekg(0); buffer = new char[size]; file.read(buffer, size); for(int i = 0; i < size; i++) sum += (int)buffer[i]; cout << sum; delete[] buffer; file.close(); return 0; } I just comment in and out the main()'s to read/write.
but i havent tried rational numbers...
I'm not sure about in C++ but I know in Java you can use a buffer reader to read in chars, ints, longs, etc, or you could read the next line in the file, and keep doing that,... It's up to you.
ok, thanks
Join our real-time social learning platform and learn together with your friends!