hi!

i have a problem..
i want to make a program the will input your name and age, and the output will count the char i been input. but my problem is i don't know what would be the code so that i can count the char i been input..
can someone help me? i dont need the whole program.. i just need the code.. thanks guys.. ^_^

Recommended Answers

All 4 Replies

string x;
x = "hello world";
cout << x.length() << endl;
int main()
{
    char input[256];
    cout << "Insert name: ";
    cin.getline(input,256);
    cout << "\nYou name is " << (int)strlen(input) << " characters long.\n";
    cin.ignore();
    return 0;
}

we prefer to use strings with getline but there we go, it's a much more reliable solution since you don't have to worry about size

string test;
getline(cin, test);
cout << test.length();

Chris

now i got it!! ^_^ thank you very much for helping me guys! it gives me a great info. thanks ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.