summaryrefslogtreecommitdiff
path: root/cpp_unicode_test/stdstring_unicode.cpp
blob: d60679c470a905117f9136105ab9c6981ec17d3f (about) (plain)
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
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>

int main( int argc, char *args[] ){
    unsigned char *fcontents = NULL;
    std::fstream *charfile = new std::fstream( reinterpret_cast<const char*>("./unicodechars.txt"), std::ios::in );
    if ( charfile->fail() ){
        std::cerr << "Failed to open file\n";
        exit( EXIT_FAILURE );
    }
    charfile->seekg( 0, std::ios::end );
    ssize_t fsize = static_cast<ssize_t>(charfile->tellg());
    charfile->seekg( 0, std::ios::beg );
    fcontents = static_cast<unsigned char*>(calloc(fsize, sizeof(unsigned char)));
    if ( fcontents == NULL ){
        std::cerr << "calloc failed\n";
        exit( EXIT_FAILURE );
    }
    charfile->read( reinterpret_cast<char*>(fcontents), fsize );
    charfile->close();
    delete charfile;
    fsize = 0;
    std::string *uchars = new std::string( "" );
    uchars->assign( reinterpret_cast<char*>(fcontents) );
    free( fcontents );
    std::cout << uchars->c_str() << "\n";
    delete uchars;
    exit( EXIT_SUCCESS );
}