Lab 9
Lab 9
2. Using the at() method, write a C++ program that reads in a string by using
getline(), stores the string in a string object named message, and then
displays the string.
Hint: After the string has been entered and saved, retrieve and display
characters, display the length of string using the( message.length())
Solution:.
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main ()
{
string str;
int i;
getline(cin,str);
int size = str.length();
return 0;
}
3. Write a C++ program that counts the number of words in a string. A word is
encountered whenever a transition from a blank space to a nonblank
character is encountered. The string contains only words separated by blank
spaces.