I have a struct:
typedef struct user { string username; vector<unsigned char> userpassword; } user_t; I need to initialize userpassword with an empty vector:
struct user r={"",?}; What should I put instead of ??
To properly initialize a structure, you should write a ctor to replace the compiler provided ctor (which generally does nothing). Something like the following (with just a few attributes): struct grupo { float transX, transY; // ...
You can actually create a vector of structs!
Both std::string and std::vector<T> have constructors initializing the object to be empty. You could use std::vector<unsigned char>() but I'd remove the initializer.
Like this:
#include <string> #include <vector> struct user { std::string username; std::vector<unsigned char> userpassword; }; int main() { user r; // r.username is "" and r.userpassword is empty // ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With