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).