Reading,writing international characters, searching string/character inside
I am using old C++ previous to C++11 standards.
I have been trying to read from a file(which includes some Turkish characters too) into a wstring,string or vector, then write the contents into another file, then read the new file's contents into a wstring,string or vector and write them into a file,then read the new file's contents...
And also I want to be able to use functions like "find()"of wstring/string/vector.
I tried so many things in the last about 10 days, playing with string,wstring,vectors but I wasn't able to do what I want.I had thought I was able to do that yesterday using vectors and copy() function(I actually read it online and did some additions to suit what I want to accomplish) but unfortunately it didn't copy whitespace characters so it was not useful for my purpose.
I have tried so many things so I am not sure which one I should write here, but one of them was:
************************
Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
vector<char>cv ;
ifstream if1 ("hello.txt",ios::binary);
if (!(if1))
{
cout << "hello.txt can't be opened!";
return 0;
}
while (!(if1.eof()))
{
cv.push_back(if1.get());
}
cv.push_back('\0');
ofstream of("file1.txt",ios::binary);
if (!(of))
{
cout << "file1.txt can't be opened!";
return 0;
}
cout << "\n\ncv: " << cv.data() << endl;
int counter=0,i=0;
vector<char>::iterator oic = cv.begin();
while (oic!=cv.end()-2 && counter<39)
{
oic++;
counter++;
of.put(cv[i]);
i++;
}
ptrdiff_t position = find(cv.begin(),cv.end(),'c') - cv.begin();
cout << "\n\nposition of h: " << position << endl;
if1.close();
of.close();
vector<char>cy ;
ifstream if2 ("file1.txt",ios::binary);
if (!(if2))
{
cout << "file1.txt can't be opened!";
return 0;
}
while (!(if2.eof()))
{
cy.push_back(if2.get());
}
cy.push_back('\0');
ofstream of2("file2.txt",ios::binary);
if (!(of2))
{
cout << "file2.txt can't be opened!";
return 0;
}
cout << "cy: " << cy.data();
counter=0;
i=0;
vector<char>::iterator oic2 = cy.begin();
while (oic2!=cy.end()-2 && counter<39)
{
oic2++;
counter++;
of2.put(cy[i]);
i++;
}
if2.close();
of2.close();
ptrdiff_t pos = find(cy.begin(),cy.end(),'c')- cy.begin();
cout << "\nposition of h " << pos;
return 0;
}
*****************
Although this code seems like reads/writes from/to files well, also when I try to find a character like 'c' ,'o' in the vector it finds it's position but unfortunately when I try to find a Turkish letter like 'ç' instead of 'c' using:
Code:
ptrdiff_t position = find(cv.begin(),cv.end(),'ç') - cv.begin();
it fails to find the letter in the vector.
How can I solve this problem?