Glorious Kale
Glorious Kale

Reputation: 1313

How do C or .NET programmers store and load strings in their programs?

I've been doing PHP and stuff for the last year; I just got into a bit of C and C++.

In the book I'm just reading, all the strings are actually in the code (I realize this is just for example, but just curious).

My interest is — is there a common way for programmers to store strings and display them? Does .NET have some predefined way of doing this — like Android does in strings file?

(In PHP, I keep them in all CSV files completely separate from code.)

Upvotes: 0

Views: 153

Answers (3)

Jonathan Leffler
Jonathan Leffler

Reputation: 754570

For C and C++, you can consider using the GNU gettext system. POSIX has a related system. Basically, they provide files stored in a known location that contain localized versions of the strings in the program. At runtime, the code collects the correct version of the message from the appropriate file for use by the program.

These are loosely related to the resource files found on Windows systems.

Upvotes: 0

Maxwe11
Maxwe11

Reputation: 486

if you asking about how to store strings in code: use preprocessor e.g.

string_literals.h

#define PATH_TO_FILE "/home/usr/filename"
/* and so on...*/

*.cpp file

#include "string_literals.h"

const char* path = PATH_TO_FILE;

Upvotes: 1

Marlon
Marlon

Reputation: 20312

Your question isn't entirely clear, but in .NET the way strings should be stored is inside a resource file (.resx). This is the way localization is done. You can see this link for more information.

Upvotes: 1

Related Questions