how to count the char you input..

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 30
Reputation: FrancisC07 is an unknown quantity at this point 
Solved Threads: 1
FrancisC07's Avatar
FrancisC07 FrancisC07 is offline Offline
Light Poster

how to count the char you input..

 
0
  #1
Jan 10th, 2009
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.. ^_^
"One more round and it's bottle to the ground"
-NOFX
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to count the char you input..

 
0
  #2
Jan 10th, 2009
  1. string x;
  2. x = "hello world";
  3. cout << x.length() << endl;
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: how to count the char you input..

 
0
  #3
Jan 10th, 2009
  1. int main()
  2. {
  3. char input[256];
  4. cout << "Insert name: ";
  5. cin.getline(input,256);
  6. cout << "\nYou name is " << (int)strlen(input) << " characters long.\n";
  7. cin.ignore();
  8. return 0;
  9. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: how to count the char you input..

 
0
  #4
Jan 11th, 2009
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
  1. string test;
  2. getline(cin, test);
  3. cout << test.length();
Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: FrancisC07 is an unknown quantity at this point 
Solved Threads: 1
FrancisC07's Avatar
FrancisC07 FrancisC07 is offline Offline
Light Poster

Re: how to count the char you input..

 
0
  #5
Jan 11th, 2009
now i got it!! ^_^ thank you very much for helping me guys! it gives me a great info. thanks ^_^
"One more round and it's bottle to the ground"
-NOFX
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC