string class object

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;


}
code]
Actuallty, numberical code 13 is for a carriage return, #10 is a line feed. You might want to look for 13 (or '\n');
Topic archived. No new replies allowed.