0

Is the following safe:

string s;
s += "dsgdf";
cout << s;

Is the string auto initialized with "" or I need to do this?

Luka
  • 1,761
  • 2
  • 19
  • 30
  • 1
    [Possible duplicate](http://stackoverflow.com/q/17738439/1883647) – ajp15243 Feb 11 '14 at 17:15
  • 1
    Effectively (but not techincally), if a class has a constructor, then a constructor is always called. `string` has a constructor, and therefore an instance of `string` has always had a constructor called. – Mooing Duck Feb 11 '14 at 17:15

1 Answers1

5

A default-constructed string is empty, yes. It's not uninitialized or in some other unsafe state.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157