Home » C++ programming language » C++ 11

Declare, assign and print the string in C++ 11 using auto keyword

Now, there is no need to declare character array to store strings, in C++ 11 we can declare a string variables by using 'auto' keyword without specifying any data type. It will automatic detect the data type according to initialized value.

Here, we will learn how we can declare a string variable using 'auto'?

Let's consider the following declaration

auto variable_name = "string";

Let's consider the following example - here we are declaring two variables website_name and location with the initial value "http://www.includehelp.com" and "New Delhi, India".

#include <iostream>
using namespace std;

int main()
	auto website_name="http://www.includehelp.com";
	auto location="New Delhi, India";
	cout<<"Website Name: "<<website_name<<endl;
	cout<<"Location: "<<location<<endl;
	return 0;	
    Website Name: http://www.includehelp.com
    Location: New Delhi, India

This program will run successfully within the compiler which supports C++ 11 features, I run this program online on TutorialsPoint Coding Ground

(C++ 11 Compiler: https://www.tutorialspoint.com/compile_cpp11_online.php).

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.