Thread: Using Cin.get()
View Single Post
Old Nov 25th, 2004, 2:00 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
#include <iostream>
#include <conio.h>

int main(int argc, char *argv[]) {
  char in[1024];
  int len = 0;
  std::cout << "Please enter a string... " << std::endl << " -> ";
  std::cin.getline(in, 1024);

  for(int i=0;i<1024;i++)
    if(in[i] != NULL)
      len++;
    else break;

  std::cout << std::endl;
  std::cout << "The length of your string is: " << len << " characters";
  
  getch(); 
}
__________________

tempest is offline   Reply With Quote