-2

I need to print the strings from this 3d matrix using an iterator.

This is the declaration

vector <string> transicoes[estados.size()][alfabeto.size()];

I tried printing like this

printf("%s", transicoes[i][j][k]);

but I get this error message:

cannot pass objects of non-trivially-copyable type

How can I do this?

EDIT: changed to cout and it works now, thanks

1 Answers1

3

The problem is that C functions are not compatible with C++ structures. Try doing this instead:

printf("%s", transicoes[i][j][k].c_str());

The c_str() call returns a const char* to a null-terminated character array with data equivalent to those stored in the string, which is a C-like string.

But if you are working with C++, you should use the stream operators << and >>. The code would then loop like this:

std::cout << transicoes[i][j][k] << endl;
pastaleg
  • 1,782
  • 2
  • 17
  • 23
  • 1
    Thanks it worked , I had to switch to from C to C++ without almost any knowledge of C++ to deal with a lot of dynamic sized vectors. So yeah... –  Jun 04 '17 at 20:53