Thread: HexDump in C++

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    Why does it gives me... this

    1>.\Source2.cpp(28) : error C3861: 'lower': identifier not found
    1>.\Source2.cpp(28) : error C3861: 'upper': identifier not found
    1>.\Source2.cpp(33) : error C2365: 'lower' : redefinition; previous definition was 'formerly unknown identifier'
    1>.\Source2.cpp(39) : error C2365: 'upper' : redefinition; previous definition was 'formerly unknown identifier'



    and this


    \Source2.cpp(18) : error C2664: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstrea m(const char *,std::ios_base:penmode,int)' : cannot convert parameter 1 from 'std::string' to 'const char *'

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Prototype your functions before trying to call them.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	string filename;
    	ifstream inData;
    	ofstream outData;
    	char buffer[1000];
    	cout << "Enter the input file name: ";
    	cin >> filename;
    	outData.open("name1.txt");
    	
    	ifstream inData(filename, ios::binary);
    	if (!inData.is_open())
    	{
    	   cout << "Unable to open file: " << filename << endl;
    	   return 1;
    	}
    
    	inData.read(buffer, sizeof(buffer));
    }
    unsigned char lower(unsigned char c)
    {
    	unsigned char one_byte;
    	one_byte = c & 0x0F;
    	return one_byte;
    }
    unsigned char upper(unsigned char c)
    {
    	unsigned char one_byte;
    	one_byte = (c & 0xF0) >> 4;
    	return one_byte;
    }
    Now Ihave only this error...

    1>------ Build started: Project: kok, Configuration: Debug Win32 ------
    1>Compiling...
    1>Source2.cpp
    1>.\Source2.cpp(17) : error C2374: 'inData' : redefinition; multiple initialization
    1> .\Source2.cpp(10) : see declaration of 'inData'
    1>.\Source2.cpp(17) : error C2664: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstrea m(const char *,std::ios_base:penmode,int)' : cannot convert parameter 1 from 'std::string' to 'const char *'
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>Build log was saved at "file://c:\Documents and Settings\adzhagar\My Documents\Visual Studio 2005\Projects\kok\kok\Debug\BuildLog.htm"
    1>kok - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    there probably some thing wrong with ifstream inData(filename, ios::binary);.. but I don't know what.
    Last edited by Kdar; 10-04-2006 at 01:54 PM.

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You've got inData declared twice. Here:
    > ifstream inData;
    And here:
    > ifstream inData(filename, ios::binary);
    And you still haven't prototyped lower and upper. You must at least declare them before they are used. You can leave the definitions at the bottom, but you need a declaration at the top.

    > ifstream inData(filename, ios::binary);
    And this should be:
    ifstream inData(filename.c_str(), ios::binary);

  5. #20
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	char upper;
    	char lower;
    	char c;
    	string filename;
    	ifstream inData(filename.c_str(), ios::binary);
    	ofstream outData;
    	char buffer[1000];
    	cout << "Enter the input file name: ";
    	cin >> filename;
    	outData.open("name1.txt");
    	
    	
    
    
    	inData.read(buffer, sizeof(buffer));
    }
    char lower(char c)
    {
    	char one_byte;
    	one_byte = c & 0x0F;
    	return one_byte;
    }
    char upper(char c)
    {
    	char one_byte;
    	one_byte = (c & 0xF0) >> 4;
    	return one_byte;
    }
    hmm.. I think I doing some thing wrong with that upprt and lower...

    also...

    when I use this, this program
    Code:
    	if (!inData.is_open())
    	{
    	   cout << "Unable to open file: " << filename << endl;
    	   return 1;
    	}
    It state that I cannot open the file...?
    Last edited by Kdar; 10-04-2006 at 02:13 PM.

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    ...........?

  7. #22
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >It state that I cannot open the file...?
    Then filename does not exist.

  8. #23
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    but it does..

    I have opened that file with some simple program..

    what do I do with those lower and upper prototypes?

  9. #24
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    ..?................

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Did you initialize filename to be the name of your input file?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 12-23-2008, 01:53 PM
  2. HexDump Programm....
    By Kdar in forum C Programming
    Replies: 4
    Last Post: 10-03-2006, 05:13 AM
  3. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM
  4. Hexdump...?
    By ylph82 in forum C Programming
    Replies: 5
    Last Post: 06-04-2002, 12:33 AM