// Various methods to initialize strings in C++
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s0("welcome to programsplusplus");
string s1(s0);
std::cout<<s1;
string s2(s0,8,3);
std::cout<<"\n"<<s2;
string s4("hello world",4);
std::cout<<"\n"<<s4;
string s5(10,'x');
std::cout<<"\n"<<s5;
string s6(10,42);
std::cout<<"\n"<<s6;
string s7(s0.begin(),s0.begin()+5);
std::cout<<"\n"<<s7;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s0("welcome to programsplusplus");
string s1(s0);
std::cout<<s1;
string s2(s0,8,3);
std::cout<<"\n"<<s2;
string s4("hello world",4);
std::cout<<"\n"<<s4;
string s5(10,'x');
std::cout<<"\n"<<s5;
string s6(10,42);
std::cout<<"\n"<<s6;
string s7(s0.begin(),s0.begin()+5);
std::cout<<"\n"<<s7;
return 0;
}
------ OUTPUT------
Please
do comment if you don't understand any part or want to know more or
just want to say thanks. I love programming and love to teach my
friends. Your suggestions and appreciation will make this blog much
better.
0 comments:
Post a Comment
Comment Here....