struct hdrs{ string sdr1; //string sdr1="1"; ? Но компилятор так ругается }; ///// hdrs myhdrs; //myhdrs.sdr1 должен равняться "1" 

    2 answers 2

    About constructors heard something?

     struct hdrs { string sdr1; hdrs() : sdr1("1") { } hdrs(const string& value) : sdr1(value) { } }; 
    • @DreamChild, hmm, I thought the designers have only classes - ololo
    • 2
      Did you happen to start with Pascal? I may surprise you, but structures can have both member functions and constructors, to which you can even apply visibility restrictions. The difference between classes and structures in something else - DreamChild
    • @ololo I myself started with him, and, if I am not mistaken, it was from there that it was a delusion that structures can have only fields. Perhaps for Pascal, this is true, (or perhaps incorrectly, I don’t remember already), but in C ++ / C # structures differ from classes not by the lack of methods and constructors - DreamChild
     myhdrs.sdr1 = "value"; 

    Well, or add a default constructor.

     public hdrs(const std::string& val):sdr1(val) { } 

    Also note that in the initialization list, all properties are initialized strictly in the order in which they appear in the class declaration.

    • @SoloMio, you need to do this in the definition of straturu - ololo