+ 3
How to take user input for character array
I wrote a program to calculate length but when I use cin.get (name, size) it gives output length as 0 in the for loop I used the condition till I is not equal to '\0'
6 ответов
+ 2
c++
+ 2
#include <iostream>
using namespace std;
int main() {
string name;
getline(cin,name);
cout<<"You entered the name: "<<name;
return 0;
}
try the above code suparna u will get it
+ 2
#include <iostream>
using namespace std;
int main() {
string name;
getline(cin,name);
cout<<"You entered the name: "<<name<<endl;
int l=name.length();
cout<<"number of character="<<l;
return 0;
}
+ 1
in which lang, u have written the code
+ 1
#include <iostream>
using namespace std;
int main() {
string name;
getline(cin,name);
cout<<"You entered the name: "<<name<<endl;
int l=name.length();
cout<<"number of character="<<l<<endl;
int c=0;
for(int i=0;name[i]!='\0';i++){
c++;
}
cout<<"length="<<c;
return 0;
}
one more way .
- 1
hello