| | |
Dynamic array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Google it and you'll get loads of good articles on that:
http://www.google.com/search?ie=UTF-...les+in+c%2B%2B
http://www.google.com/search?ie=UTF-...les+in+c%2B%2B
I wrote one as follows.
Well I read a binary file using this, the command prompt is really mad. It,s not displays as a binary code, I mean bunch of zeros and ones.
Can you say where I'm going wrong.
string line;
ifstream fileread ("path to the binary file");
while(! fileread.eof())
{
getline(fileread, line);
cout << line << endl;
}
fileread.close();Well I read a binary file using this, the command prompt is really mad. It,s not displays as a binary code, I mean bunch of zeros and ones.
Can you say where I'm going wrong.
Last edited by eranga262154; Sep 5th, 2007 at 3:40 am. Reason: Incorrect
•
•
Join Date: Aug 2007
Posts: 10
Reputation:
Solved Threads: 2
Another article from google
http://www.angelfire.com/country/ald...aryFileIO.html
http://www.angelfire.com/country/ald...aryFileIO.html
•
•
•
•
I wrote one as follows.
string line; ifstream fileread ("path to the binary file"); while(! fileread.eof()) { getline(fileread, line); cout << line << endl; } fileread.close();
Well I read a binary file using this, the command prompt is really mad. It,s not displays as a binary code, I mean bunch of zeros and ones.
Can you say where I'm going wrong.
1: Binary data is not string data. You should probably be using a char array.
2:
while(! fileread.eof()) will not work properly. See this (feof() is the same as .eof()) The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
•
•
1: Binary data is not string data. You should probably be using a char array.
C++ Syntax (Toggle Plain Text)
ifstream fileread ("path to the binary file"); string contents; char ch; // Get the binary data while ( fileread.get( ch ) ) { contents.push_back( ch ); } // Print the binary data as hex for ( int i = 0; i < contents.size(); ++i ) { cout<< hex << int( contents[i] ) <<" "; } fileread.close();
The truth does not change according to our ability to stomach it.
![]() |
Similar Threads
- get length of a dynamic array (C++)
- Sorting 2D Dynamic array of integers , Snake Style (C)
- works for static need help to make it dynamic (C++)
- dynamic array of structures problem (C++)
Other Threads in the C++ Forum
- Previous Thread: passing arrays / updating object arrays
- Next Thread: using if-else
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






