function Length
hello guys.
I wrote this assignment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
//---------------------------------------------------------------------------
#include<iostream.h>
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
int count=0;
int index;
string Whole;
char single;
cout<<"please enter words:"<<endl;
cin>>single;
for(index =1; index<= Length(Whole); index+1)
{
if (Whole[index]== single)
count = count+1;
}
cout<<"Occurances = "<<count<<;
getchar();
return 0;
}
//---------------------------------------------------------------------------
|
then the errors are:
[C++ Error] Unit1.cpp(18): E2268 Call to undefined function 'Length'
[C++ Error] Unit1.cpp(25): E2188 Expression syntax
how should I make the call to function Length?
Thanks
Try Whole.size() (although it doesn't seem like whole is anything right now...)
Change line 25 to.
cout<<"Occurances = "<<count;
If Length is a function you wrote you should likely post it up too.
The function "length()" is a member function of std::string objects so you would call it like this:
Whole.length()
and yes it IS caps sensitive. See here:
http://www.cplusplus.com/reference/string/string/length/
Your integer "index" should start at zero unless there is a reason that you are skipping the first character in your string.
The string "Whole" is not holding any data so "count" will always be zero.
Muckle ewe is right about the error on Line 25, you need to get rid of that last stream operator.
Topic archived. No new replies allowed.