Thread: opening file problem, encoding?

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    22

    opening file problem, encoding?

    Hi all,

    got another problem using open of ifstream or fopen or whatever on a file in my filesystem.
    My program isn't able to open these files, they are encoded ... strange? At least for me

    When doing a 'dir' in the console where the files are, this is the output:
    28.08.2009 09:52 3'016 r├╝mm├╝k_000080118887.sdtid
    26.11.2009 16:04 3'063 ├ä├û├£├Â├ñ├╝_000080118889.sdtid

    When redirection the output to a file and opening it with notepad, this is the output:
    28.08.2009 09:52 3'016 rümmük_000080118887.sdtid
    26.11.2009 16:04 3'063 ÄÖÜöäü_000080118889.sdtid

    When looking at them in the explorer it looks like in the picture attached. I've got a standard english Win XP installed, nothing special. The files were made by a third party product, I can't change the way they are encoded, and I can't rename them by hand as I need to run an automation on many of these files...

    This is my code I use to open the file.

    Code:
    int convert_file(char *fname)
    {
    	ifstream input;
    	ofstream output;
    	string line;
    
    	//setlocale(LC_CTYPE, "");
    	//setlocale(LC_CTYPE, ".ACP");
    	//printf ("Locale is: %s\n", setlocale(LC_ALL,NULL) );
    
    	input.open(fname, ios::in);
    
    	if(input.is_open() == false)
    	{
    		cout << "File could not be opened!" << endl;
    		return 1;
    	}
    Anybody an idea?...
    Chears
    Rafael

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Where does the 3rd party app that creates these files come from?

    Looks like it is using a character set your PC does not have installed / cant display.

    What error does GetLastError() return?

    Can any other app open the file?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The filenames have Unicode characters in them that the current font can not display. And since there is no gaurentee that the current ACP can even represent those characters, you should handle the filenames using Unicode (wchar_t/WCHAR strings) only.

    gg

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    22
    Hi

    the third party application is the RSA Authentication Manager from RSA Security.
    GetLastError returns 2, meaning ERROR_FILE_NOT_FOUND.

    I noticed that the filenames have Unicode characters, therefore I already tried using wchar_t/WCHAR strings, but that didn't make any difference. Therefore I'm confused

    And yes, other Apps can open the file, I can use Wordpad/Notepad whatever to display the content...

    Regards

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Here's how you can generate a UTF16LE encoded text file containing the Unicode file names of the files in question: cboard.cprogramming.com/cplusplus-programming/121667-isapi-unicode-filenames-2.html

    The wchar_t's in that generated text file are what you need to give to CreateFileW(), _wfopen(), or fstream::open(const wchar_t*).

    You should also be using a filesystem that supports Unicode, like NTFS.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM