- I think you know there’s only three lines here
[['3325309756482910474', 'CARRO', '2506794813021649539', '618.57'],
['3325309756485249504', 'MOTO', 2506794813021649539', '649.32'],
['3328687456208678517', 'BIKE', '2506794813021649539', '649.43']]
and 4 in the post and that is a function in C, despite having used the tag C++
In C++ use a class. It’s simpler.
auto
auto
in C has another meaning. It is not a type definition. In C++ auto does not apply to that context, as the compiler must have said.
In C++ you can write
string m[4][4] =
{
{ "3325309756482910474", "CARRO", "2506794813021649539", "618.57"} ,
{"3325309756485249504", "MOTO", "2506794813021649539", "649.32" },
{ "3328687456208678517", "BIKE", "2506794813021649539", "649.43" }
};
If you prefer to declare "Matrix" you can even write
using Matriz = string[4][4];
As in this example
#include <iostream>
using namespace std;
using Matriz = string[4][4];
int main(void)
{
string m[4][4] =
{
{ "3325309756482910474", "CARRO", "2506794813021649539", "618.57"} ,
{"3325309756485249504", "MOTO", "2506794813021649539", "649.32" },
{ "3328687456208678517", "BIKE", "X506794813021649539", "649.43" }
};
Matriz uma{};
uma[3][3] = m[2][2];
cout << "M[3][3] = \"" << uma[3][3] << "\"\n";
return 0;
}
That shows the expected
M[3][3] = "X506794813021649539"
Use a class and write the methods as you need them. Or even the operators for Matrix.
And where is the code you tried and which error was reported? Should you not use
{
and}
in place of[
and]
?– anonimo
I added the code. The error reported is: "the expression must have pointer-to-object type".
– Bruna Castro
But
m
is a string or an array of strings?– anonimo
An array of strings. Is it right for me to put m[]? And how, from that, I could create an array?
– Bruna Castro
@Brunacastro you declared a string not a string array the right one would be
string m[4][4];
, in the second row for a 4x4 Matrix.– user72726
@user72726, I replaced it and it worked. However, the print gets strange characters:
·┘8·┘T·┘p·┘
î·┘¿·┘─·┘Ó·┘
³·┘¹┘4¹┘P¹┘
l¹┘ê¹┘ñ¹┘└¹┘
– Bruna Castro
I must import some library?
– Bruna Castro
Since you are programming in C++, consider using
cout
instead ofprintf
. But if you really want to use printf, you should first convert the string from C++ to C before printing. Ex:printf("%s", m[i][j].c_str())
– user72726
It gave right, vlw to have helped @user72726!
– Bruna Castro