T71.StringClassandStringFunction
1
#include<iostream> #include<string> //gives you string functions using namespace std; int main(){ string bucky; cin>>bucky; //end of input is determined by white space cout<<"the string i entered is:"<< bucky<< endl; string x; getline(cin,x); //the end of the input is determined by a new line cout<<x<<endl; string s1("hampster "); string s2; string s3; s2 = s1; //identical things s3.assign(s1); cout<< s1 << s2 << s3 << endl; string s1 = "omgwtfbbq"; cout << s1.at(3) << endl; //strings are array of characters for(int x=0; x<s1.length();x++){ cout<<s1.at(x); } }
-
Upload
tim-acosta -
Category
Documents
-
view
212 -
download
0
description
asd
Transcript of T71.StringClassandStringFunction
![Page 1: T71.StringClassandStringFunction](https://reader031.fdocuments.in/reader031/viewer/2022020506/563dba09550346aa9aa22303/html5/thumbnails/1.jpg)
#include<iostream>#include<string> //gives you string functionsusing namespace std;
int main(){
string bucky; cin>>bucky; //end of input is determined by white space cout<<"the string i entered is:"<< bucky<< endl; string x; getline(cin,x); //the end of the input is determined by a new line cout<<x<<endl;
string s1("hampster "); string s2; string s3; s2 = s1; //identical things s3.assign(s1);
cout<< s1 << s2 << s3 << endl; string s1 = "omgwtfbbq"; cout << s1.at(3) << endl; //strings are array of characters for(int x=0; x<s1.length();x++){ cout<<s1.at(x); } }