0

I have a string from an array:

this->ramStringInput[titleIndex][0];

and an string..int which is an index from a loop:

std::to_string(titleIndex)

I've tried:

this->ramStringInput[titleIndex][0] + std::to_string(titleIndex)

but that is a literal 'Title1'. Which is not what I'm trying to do.

Is there a way to concat those two vars to access this->Title1?

getline (cin, this->ramStringInput[titleIndex][0] + std::to_string(titleIndex)); //not working

vs

getline (cin, this->Title1); //Would work, but can't do from a loop.
  • 3
    You can't. `this->Title1` is an offset known to the compiler at compile-time; the actual binary doesn't store that as anything more than debugging metadata at most. C++ isn't a high enough level language to look up properties by string names (that's a feature of scripting languages like Perl, Python and JavaScript, where their objects are usually thin-wrappers around string keyed hash maps); if you want to be able to do that, use `map`/`unordered_map` or the like, keyed by `string`. – ShadowRanger Jan 10 '18 at 01:26
  • You can only do this at compiler time. Given your variable names it looks like this is runtime input, so there’s no way to use it there. If all the information you need is available at compile time, it might be possible to get something to work, but it would be difficult to read or maintain. – Daniel H Jan 10 '18 at 01:28
  • Providing the information at compile is more trouble than it's worth in this case, I ended up using maps on that project. Knew what I wanted, didn't know what it was called. Thanks, both of you. –  Jan 24 '18 at 18:09

0 Answers0