use getline to read char array based string : Char Array « Data Type « C++






use getline to read char array based string

  
#include <iostream>
#include <string >
using std::cout;  
using std::cin;
 
int main() 
{
  char s1[40],s2[40],s3[40];
  int size;
  cout << "Please enter a word \n";
  cin.getline(s1,40); 
  cout << "Please enter another word  \n";
  cin.getline(s2,40);
  size = strlen(s1);
     
  strcat(s1,s2);
  cout << "The length of the first string you entered is" << size << "\n";
  cout << "Both strings you entered are " << s3<< "\n";
  return 0;
}
  
    
  








Related examples in the same category

1.use char array as string
2.Use cin.getline to read a char array based string
3.Char array and char pointer
4.Use new operator to allocate memory for char array