Let us see the String length Program Using Structure and built-in function in C++.
Structure and built-in function in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//structure with user define function - demonstration by t4tutorials.com #include<iostream> #include<string.h> using namespace std; struct lengthstring { char str[10]; }; int main() { lengthstring s; int len; cout<<"please enter your desired string"<<endl; cin>>s.str
; len=strlen(s.str); cout<<"The length of your desired string is:"<<len<<endl; return 0; } |
Output
please enter your desired string
Hi
The length of your desired string is: 2