Hello, I need help with me homework. It's probably something simple. My program is supposed:
1) read lines from a file (rain.txt)
2) find the shortest and longest lines (I used strlen())
3) return the line number of shortest and longest and well as their length
4) show the avg number or characters per line
So far I'm just trying to read the lines from the file. When I go to compile this is the error I receive:
error C2664: 'strlen' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
do i need a type conversion in here? what am I doing wrong? oh yeah, here's my code: :o
#include <iostream> // cin, cout
#include <fstream> // ifstream, ofstream
#include <string> // string, getline()
#include <cassert> // assert()
#include <cfloat> // DBL_MIN and DBL_MAX
using namespace std;
int main()
{
cout << "This program computes the number, maximum, minimum, and\n"
"average of an input list of stings and characters in one file\n";
ifstream inStream;
inStream.open("rain.txt");
if(!inStream.is_open())
{ cout << "Error opening file"; exit (1); }
int members, count = 1;
double maximum = DBL_MIN,
minimum = DBL_MAX;
string lyrics;
while (!inStream.eof() )
{
getline(inStream, lyrics);
cout<<count<< ") " <<lyrics <<"\n";
string bob = lyrics;
members = strlen(bob);
count++;
if ( inStream.eof() ) break;
if (members < minimum)
minimum = members;
if (members > maximum)
maximum = members;
}
inStream.close();
cout << count;
return 0;
}