Reading a file with UCS2 (csv) data.

Hi ,
I am facing issue reading a file which contains comma seperated ucs2 data in it. I need a program which reads the file contents and split(tokenize) each line in the file.
I used wifstream but could not read the contents of file properly. I have paste a test program below ... any help is appreciated.

========================================
#include <iostream>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <string>
#include <locale>
#include <vector>

using namespace std;

typedef std::string String;

typedef std::vector <String> CSVRow;

int main()
{
std::wifstream inf2("data.txt");
std::wstring contents_wide;
CSVRow csvRow;

getline( inf2, contents_wide, wchar_t(0) ); //doesn't work
wcout << contents_wide;

boost :: split(csvRow, contents_wide, boost::is_any_of(","));
cout <<"SIZE : " << csvRow1.size() << '\n';
}
========================================
I'm not a great expert in this and I don't know much about UCS-2 but it is a 2-byte character encoding. One problem with the C++ standard is that wchar_t is not always 2 bytes big. In fact on my system it is 4 bytes.

So on my system wchar_t is not appropriate for reading UCS-2 data.

You might consider reading in using the normal character streams and converting every two bytes to a single wchar_t afterwards.
Topic archived. No new replies allowed.