C++ Strings: Prepared By: Rowena S. David
C++ Strings: Prepared By: Rowena S. David
#include <iostream>
using namespace std;
int main()
{ char str[100];
cout << "Enter a string: ";
cin >> str;
cout << "You entered: " << str << endl;
cout << "\nEnter another string: ";
cin >> str;
cout << "You entered: "<<str <<endl;
return 0;
}
C++ program to read and display an entire line entered by user.
#include <iostream>
using namespace std;
int main()
{
char str[100];
cout << "Enter a string: ";
cin.get(str, 100);
#include <iostream>
getline() function takes the input stream
using namespace std; as the first parameter which is cin and str
as the location of the line to be stored.
int main()
{
// Declaring a string object
string str;
cout << "Enter a string: ";
getline(cin, str);