I have to write a function that accepts a C-string as an argument and returns the length of the C-string as a result. The function should count the number of characters in the string and return that number. This is the code I have:
#include <iostream>
#include <cstring>
#include <string>
usingnamespace std;
int StringLength(string StrName, int length);
int main()
{
string bobString;
int length;
cout << "Input a string\n";
cin >> bobString;
StringLength(bobString, length);
return 0;
}
int StringLength(string StrName, int length)
{
length = strlen(StrName);
cout << "The length of the string is " << length << endl;
system("PAUSE");
return length;
}
And this is the error I get:
error C2664: 'strlen' : cannot convert parameter 1 from 'std::string' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I thought the 1st parameter in the function header (StrName) had to be a string, since the string I am inputting in the main (bobString) is a string, right?