Reputation: 302
I'm here to ask you help with a code i'm working on.
I'm converting a tool from C++ to C#.
I've almost completed everything, but...
There's the code in C++ of Struct and how the tool use it:
struct Line
{
uint16_t Magic;
std::vector<std::string> Params;
}
This is the structure, the tool use like this in a switch:
case MAGIC_FUNCTION_BEGIN:
{
pLine -> Params[0][8] = ' ';
Output << pLine -> Params[0];
pLine -> Params.erase(pLine->Params.begin());
Output << GenParams(pLine->Params) << '\n';
break;
}
So, now, the question is:
How is possible that use pLine -> Params[0][8] if it is a simple string vector?
Thanks!
Thank you so much for the answer.
I resolved in C# by setting it as:
char[] text = pLine.param[0].ToCharArray();
text[8] = ' ';
pLine.param[0] = text.ToString();
Now i've to ask something else about this code...
What it means when it does
pLine -> Params.erase(pLine->Params.begin());
How can be converted to C# something like erase and begin?
Thanks :)
Upvotes: 0
Views: 1170
Reputation: 310950
The type of expression Params[0]
is reference to an object of type std::string. Shortly speaking Params[0]
is an object of type std::string
and applying the second subscript operator Params[0][8]
you will get the character at position 8.
That it would be more clear you could split statement
pLine -> Params[0][8] = ' ';
into two statements
std::string &s = pLine -> Params[0];
s[8] = ' ';
In fact you have two containers where one container is put in another container.
Upvotes: 0
Reputation: 13818
std::string
has an operator[]
for accessing the individual elements.
pLine->Params[0][8]
means "access the 9th character of the first parameter in pLine
". In this case, it's set to a space character ''.
Upvotes: 1