i need to know how to "write a function to count the number of lines entered using a string class object. consider a line as any sequence of characters followed by the enter key"
all i have so far is:
#include <iostream>
#include <stdafx.h>
#include <string>
usingnamespace std;
int main()
int countLines(string stng)
{
int index, count = 0;
index = stng.find((char)10); // 10 is the numerical code for Enter key
while(index < stng.length())
{
if(index = stng.find((char)10, index+1))
count++; // this assumes even last line
ends w/Enter
}
string message;
cout << "Enter a string:\n";
getline(cin, count);
return count;
cout << "The number of strings entered is:\n"
<< message << endl;
}