Hello,
I have the following problem:
Let's pretend we have two text files:
1 2
|
list_utf8.txt (UTF-8 coded, 30 bytes in size)
list_ansi.txt (ANSI coded, 24 bytes in size)
|
Both contain just one line:
C:\Testfile with äöü.dat
This file does really exist in C:\Testfile with äöü.dat
Now I read both files with Boost, print the input and check if the file does exist. This is my outcome:
(Picture)
http://home.arcor.de/gabbafrog/ccc.png
As you can see, it doesn't print the special chars correctly (this isn't that important), but what the biggest problem is: It doesn't find the file, when it reads from the UTF-8 file!
What do I have to do or change in the code to make it work, so that it finds the existing file?
I guess I have to change something with "string"? Or do I have to tell boost in some way, that the file being read is UTF-8 format? The reason I use boost is that I want the program to be portable (Windows and Linux). Please help me, I am a beginner in C++.
Thank you!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string/predicate.hpp>
using namespace std;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
path p_list_utf ("C:\\list_utf8.txt");
boost::filesystem::ifstream inFileUTF(p_list_utf);
while (inFileUTF)
{
string s;
getline(inFileUTF,s);
if (inFileUTF)
{
cout << p_list_utf << endl << s << endl;
if ( exists(s) )
{
cout << "File exists!" << endl;
}
else
{
cout << "File DOES NOT exist!" << endl;
}
}
}
path p_list_ansi ("C:\\list_ansi.txt");
boost::filesystem::ifstream inFileANSI(p_list_ansi);
while (inFileANSI)
{
string s;
getline(inFileANSI,s);
if (inFileANSI)
{
cout << p_list_ansi << endl << s << endl;
if ( exists(s) )
{
cout << "File exists!" << endl;
}
else
{
cout << "File DOES NOT exist!" << endl;
}
}
}
return 0;
}
|