Hi everyone. I'm working on an assignment for my CS class and I'm having a few issues coming up with how to do my few remaining problems. The assignment specifies that we may not use recursion, loops, or switch statements; only the STL. Any help or hints would be greatly appreciated as I'm out of ideas on how to get the methods to work.
1. Find the total length of all strings in a set. The assignment suggests using the accumulate algorithm. Here's what I have so far:
1 2 3 4 5 6 7 8
int total_string_length( const set<string>& data )
{
int result = accumulate(data.begin(), data.end(), 0, ...);
//This is the line I'm having issues with, I thought that a
//string.length() for the 4th argument would work but it does not.
return result;
}
2. Determine the number of lines in a file. The assignment suggests using the count algorithm and istreambuf_iterator<char>. Unfortunately I'm not even sure where to begin with this one, I guess I'm not sure how the istreambuf_iterator works and how to use it.
Thanks for any help that anyone is willing to give.