0

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.)

Marlon
  • 19,924
  • 12
  • 70
  • 101
Glorious Kale
  • 1,273
  • 15
  • 25
  • In C and C++, GNU's [`gettext`](http://en.wikipedia.org/wiki/Gettext) is a popular method of handling string constants, and there's a rich set of tools available to work with the string database files. There are also ports for Windows. – Kerrek SB Sep 02 '12 at 16:58
  • As for your actual question, in Windows it's common to store strings in "resource files" (file ending `.rc`), but storing them in other kind of text files works as well and is more portable. – Some programmer dude Sep 02 '12 at 16:58
  • So...your question should really be "is there a library/existing code in C/C++ for parsing CSV files" ? – tbert Sep 02 '12 at 17:26
  • What does .NET have to do with this question? Or by C/C++ do you mean C++/CLI (the .NET version of C++)? The question is unclear. – Marlon Sep 02 '12 at 17:39

3 Answers3

1

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;
Maxwe11
  • 486
  • 4
  • 12
1

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.

Community
  • 1
  • 1
Marlon
  • 19,924
  • 12
  • 70
  • 101
0

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278