I'm trying to write a program that returns the number of characters in a string. As I was writing my program, I've noticed that there's a bug in the string class. The length always returns 0.
Say my program is this:
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
string fname;
string lname;
string fullname = fname + lname;
int length=fullname.size();
cout<<"Name Registration";
cout<<"\n\nPlease Enter your first name";
cin>>fname;
cout<<"\n\nPlease Enter your Last name\n";
cin>>lname;
cout<<"\n\nYour Full Name is "<<fname<<" "<<lname<<".\n\nYour Name contains "<<length<<" words";
}
Aucun commentaire:
Enregistrer un commentaire