First of all, your indentation needs work.
Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
vector < wchar_t >cv;
wifstream 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');
#if 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++;
}
#endif
ptrdiff_t position = find(cv.begin(), cv.end(), 'c') - cv.begin();
cout << "\n\nposition of c: " << position << endl;
ptrdiff_t position2 = find(cv.begin(), cv.end(), L'ç') - cv.begin();
wcout << L"\n\nposition of ç: " << position2 << endl;
if1.close();
#if 0
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;
#endif
return 0;
}
Second, you might need to think about how your text file is encoded (UTF8, UTF16, UCS2 ...)
Eg.
Code:
$ hd hello-16le.txt
00000000 54 00 68 00 69 00 73 00 20 00 69 00 73 00 20 00 |T.h.i.s. .i.s. .|
00000010 63 00 0a 00 54 00 68 00 61 00 74 00 20 00 69 00 |c...T.h.a.t. .i.|
00000020 73 00 20 00 e7 00 0a 00 |s. .....|
00000028
$ hd hello.txt
00000000 54 68 69 73 20 69 73 20 63 0a 54 68 61 74 20 69 |This is c.That i|
00000010 73 20 c3 a7 0a |s ...|
00000015
The short answer is to use wide characters and wide streams - as I've done in your code.
Code:
$ g++ foo.cpp
$ hd hello.txt
00000000 54 68 69 73 20 69 73 20 63 0a 54 68 61 74 20 69 |This is c.That i|
00000010 73 20 c3 a7 0a |s ...|
00000015
$ ./a.out
position of c: 8
position of �: 20
$ cat hello.txt
This is c
That is ç