// demonstrates definition and elementary operations with structures // Mikhail Nesterenko // 10/14/2009 #include #include using std::cout; using std::endl; using std::string; struct example{ int a; string b; }; int main(){ example s1={1, "one"}; // initializing structure variable at declaration cout << "Members of structure variable s1 are: "; cout << "s1.a=" << s1.a << " s1.b=" << s1.b << endl; example s2; s2=s1; // copying the contents of the structure variable as whole cout << "Members of structure variable s2 are: "; cout << "s2.a=" << s2.a << " s2.b=" << s2.b << endl; // members can be manipulated as scalar variables ++s2.a; s2.b += " and another"; cout << "Members of structure variable s2 are: "; cout << "s2.a=" << s2.a << " s2.b=" << s2.b << endl; }