| | |
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 based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






