Hello, I wrote small function which translates text in my application:
map<string,stri ng> localization;
1 string: universal identifier of localized text
2 string: text to localize -
const char* App::localize(string local)
-
{
-
if (!localization.count(local))
-
{
-
return "CANNOT FIND THIS TEXT";
-
}
-
else
-
{
-
return localization[string(local)].c_str();
-
}
-
}
The problem is when I change language of my application at runtime -> It loads new values into "map<string,str ing> localization;" and erases the old ones so all constant char pointers become invalid.
3 1683 Savage 1,764
Recognized Expert Top Contributor
Hello, I wrote small function which translates text in my application:
map<string,stri ng> localization;
1 string: universal identifier of localized text
2 string: text to localize -
const char* App::localize(string local)
-
{
-
if (!localization.count(local))
-
{
-
return "CANNOT FIND THIS TEXT";
-
}
-
else
-
{
-
return localization[string(local)].c_str();
-
}
-
}
The problem is when I change language of my application at runtime -> It loads new values into "map<string,str ing> localization;" and erases the old ones so all constant char pointers become invalid.
Then don't use constant char pointers.
BTW,welcome to TSDN!
Savage
Then don't use constant char pointers.
:-) thank you for this advice, but unfortunately I have to use them. I am using FLTK library for the gui and its widget labels must be constant char*s
Savage 1,764
Recognized Expert Top Contributor
:-) thank you for this advice, but unfortunately I have to use them. I am using FLTK library for the gui and its widget labels must be constant char*s
Is that function part of some class?
If it is,u can make a instance of the class when new language is selected,so that constant will remain valid.
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: g |
last post by:
Hi all.
Maybe this question has been asked many times before, but I was not able to find
any pointer. I apologize in advance, for it refers to a particular standard
library implementation (GNU C++ version 3.x), but perhaps it's more general than
that.
The following program (to be compiled with g++ 3.x, 2.9x is not enough)
#include <iostream>
#include <string>
|
by: Manisha |
last post by:
Hi,
I am creating a C++ dll which is used to process data passed to it
through one of its exported functions. It should be able to process
160 simultaneous requests. For this reason, I have initiated 10 child
threads from the main thread and maintaining a queue of nodes
containing the data to be processed.
The queue node strucute is as follows:
struct SQueueNode
|
by: lovecreatesbeauty |
last post by:
Hello experts,
Is const_cast only applied to pointers or references? If I have a
constant object, then how can I remove constant attribute from it?
#include <vector>
#include <string>
using namespace std;
|
by: drj0nson |
last post by:
What is the right way of creating a string/char array and assigning to
a char* which is then used in a function call. Thought it would be
quite nice to avoid a memory leakage /core dump.
1 Header with char* x
2 Class includes header
3 In Class member function I want to :
a)conditionally create a string ie populate x
|
by: sposes |
last post by:
Im very much a newbie but perhaps somehone can help me. Ive been
searching for a way to convert a std::string to a unsigned char*
The situation is I have a function that wants a unsigned char* and I
want to give it a std::string
no matching function for call to `MD5::update(std::string&, size_t)'
candidates are: void MD5::update(unsigned char*, unsigned int)
void PrintMD5(string str){
| |
by: SteelSide |
last post by:
Ive searched and searched,but havent been able to get it to work.
-----------------
#include <iostream>
using namespace std;
std::string tempHostNameStr = "s1e2.hidden.thingy.org";
char szHostName;
|
by: arv6004u |
last post by:
Hi,
I have created Map Data stacture. Each map Entry contains hostname and it's value.
I have traversed the map using iterator then i want to delete specific hostname entry and to change the remaining map value for the existing hostnames.
My sample code as follows.
typedef struct _CAAMT_Credentials
{
|
by: silverburgh.meryl |
last post by:
In my code, I have an array of char* pointer which is populated
statically:
void function1() {
char *ppsz_argv2 = { "abc" ,
"def",
"dummy"};
//...
}
|
by: C++Liliput |
last post by:
I have a class of the type
class A
{
private:
std::string data;
.......
public:
const char* toString();
};
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |