Aug 5, 2016 at 9:05pm UTC
I have googled and have not found anything relating to this, or am just looking for the wrong thing.
I have a struct
1 2 3 4 5 6 7 8 9 10 11 12
enum LANG_ID_TYPE {
FIRSTLANG, //0
ENGLISH = FIRSTLANG, //0
SPANISH, //1
LASTLANG = SPANISH //1
};
typedef struct {
int LitId ;
std::string Literals[LASTLANG+1] ;
} LiteralStruct ;
and when used statically is populated like so:
1 2 3 4 5 6 7 8 9 10
const int NUM_SORT_STRINGS = 23;
const LiteralStruct SortStrings [ NUM_SORT_STRINGS ] = {
{ 0, //error type id
"All" , //english
"Todos" //spanish},
{ 1,
"Horse" ,
"Caballos" }
}
and accessed as:
TheString = ErrMsgs[ ErrorId ].Literals[ LangId ].c_str() ;
I am trying to do this dynamically by reading a file, binary so users cannot modify. Right now I am not worried about the binary part. I just need to get this populated.
This is what I have tried:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
void LoadCSVTranslations::readStringValuesToMap() {
int delimeterPos;
std::string translatedValueString,translationKeyname;
ifstream litfile;
litfile.open("..//..//langlits.dat" , ios::in);
int i = 0;
string line;
string outstr;
LiteralStruct ErrMsgs[ MAX_ERR ] = {} ;
int t = FIRSTLANG;
while (getline(litfile, line)){
delimeterPos = line.find(',' );
translationKeyname = line.substr(0, delimeterPos);
translatedValueString = line.substr(delimeterPos+1);
if (atoi(translationKeyname.c_str()) == 38 && t < LASTLANG)
t++;
if ( atoi(translationKeyname.c_str()) >= 0 && atoi(translationKeyname.c_str()) <= 38)
{
ErrMsgs[ atoi(translationKeyname.c_str()) ].LitId = atoi(translationKeyname.c_str());
if ( t > 0 && t < LASTLANG+1)
ErrMsgs[ atoi(translationKeyname.c_str()) ].Literals->append("," );
ErrMsgs[ atoi(translationKeyname.c_str()) ].Literals->append("\"" + translatedValueString + "\"" );
}
}//endwhile
litfile.close();
}
I have also tried:
1 2
ErrMsgs[ atoi(translationKeyname.c_str()) ].Literals[ t ].append("\"" + translatedValueString + "\"" );
ErrMsgs[ atoi(translationKeyname.c_str()) ].Literals[ t ] = "\"" + translatedValueString + "\"" ;
I figured this would work and populate the Literals[2] (LASTLANG+1). Am I missing something or misunderstanding std::string name[] and how it works?
Last edited on Aug 5, 2016 at 9:13pm UTC
Aug 5, 2016 at 11:34pm UTC
So what's the problem? Are you getting compiler errors? Does it not work properly?
Aug 8, 2016 at 8:08am UTC
sorry. the problem is that when t changes from 0 to 1 and I do a watch on ErrMsgs, it only shows the recent assignment and there is not array for me to click on as I would expect.
Even though when I hover over Literals it does show it as an array Literals[ 2 ] it would appear that Literals[ t ] doesn't work to assign value to new array value.
Last edited on Aug 8, 2016 at 8:17am UTC