iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

How to Declare a String in C++

104 24

    Add the std Namespace

    • 1). Add the std namespace with the "using" keyword. For example, type:

      using namespace std;

    • 2). Declare a string, optionally using a constructor to assign a starting value. For example, type:

      using namespace std;

      string example_string;

      string constructor_string("This is the string's text.");

    • 3). Assign values to strings as you would other variables. Strings can be added to each other and assigned using the normal +, = and += operators.

      using namespace std;

      string example_string;

      string constructor_string("This is the string's text.");

      example_string = "This is the string's assigned value.";

      example_string += " This text was added to the string's original value."

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Health & Medical"

Leave A Reply

Your email address will not be published.