can anyone help me "write a function to count the numbeer of lines entered using a string class object. consider a line as any sequence of characters followed by the enter key" for an asignment?
here is what i have so far:
[code][/#include <iostream>
#include <stdafx.h>
#include <string>
using namespace 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;