strings and searching

I took a class for c++ and fixing this is one of the debugging practices we have to do. I spent 3 hours reading the text, searching google, and changing things to see if i can figure it out. Any help, or links to relevant webpages i could learn from would be very appreciated. Don't even know what I'm supposed to fix =[. I just get errors like:
error C3861: 'length': identifier not found
error C3861: 'find': identifier not found
error C3861: 'substr': identifier not found


#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main ( )
{
String stateName = "Mississippi" ;

cout << stateName << " has " << length( ) << " characters\n";

cout << "First occurance of word is\" is at position: " << find("is") << endl;

cout << "The first four characters are:\t\t" << substr( 1, 4 ) << endl;

cout << "The next two characters are:\t\t" << substr( 5, 2 ) << endl;

cout << "Charters start at position 9 are:\t" << substr( 9, 5 ) << endl;

_getch();
return 0 ;
}
First problem I see is that you used String stateName = "Mississippi" ; instead of string stateName = "Mississippi" ;.

Other than that, the length, find and substr are all functions of the string class. You need to call them from a string object.

In other words change them to

1
2
3
stateName.length()
stateName.find()
stateName.substr()


Also, you should put your code inside the code tags
[code][/code]
to make it easier to read.
Last edited on
length( )
Length of what?
find("is")
Where are we searching?
substr( 1, 4 )
What is original string?
Thank you, working and seems obvious now. I'll remember the code tags if/when there's a next time.
Topic archived. No new replies allowed.