ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I understand that you might not be able to enter the values in the compiler, but since you are reading them from file in
the first place, you could set up a resource file where you could store these characters and read them in at the beginning of
the program.
I haven't tested this out because I don't have Turkish fonts, but it seems to me like it should work.
actually I already tried that, the thing is I also used the replace function like this:
Code:
replace(str_in.begin(), str_in.end(), 'ö', 'o')
but in this case if str_in's value is given in the source code, there is no problem but if I type it in the console (with cin), It doesn't work at all.
So what you're saying will surely work, but not with a input string :/
The problem is that for function templates, the template parameters are deduced by the compiler based on the types you are passing in as parameters. The replace function is really a template function. It looks like:
Code:
template <class ForwardIterator, class T>
void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value)
So if you pass in iterator, iterator, int, char, it looks for the prototype
Code:
void replace(iterator, iterator, int, char)
Since the last two parameters are always the same type, the compiler can't find it, and it barks at you.
If you are going to be using characters outside the ASCII and extended ASCII set (i.e. characters that require more than 8 bits), you should probably consider using wstring instead of string. However, the global streams cin, cout, and cerr used for console input, output, and error are only capable of handling char data-- not wchar_t data.
Here is my previous example, tweaked to use a wstring instead of a string. This uses the *NIX device /dev/tty to write to the console, since I can't send a wide-character string to a cout (a character stream).
Code:
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
int main()
{
using std::wstring;
using std::wofstream;
using std::endl;
using std::replace;
wstring s(L"Hejjo Worjd!");
replace(s.begin(), s.end(), L'j', L'l');
// Create a wide-character output stream to write to the console.
wofstream wcout("/dev/tty");
wcout << s << L'\n';
return 0;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.