I got this code sent to me, and am working with a friend to see what the problem is. We can't seem to run it at all the even try to find the problems with its errors.
It just says the system cannot find the file specified. I was told to change something towards the beginning of the code to make it run at least, but still can't figure it out.
/*
Mississippi has 11 characters
First occurance of word "is" is at position: 1
The first four characters are: Miss
The next two characters are: is
Charters start at position 9 are: pi
*/
#include <iostream>
#include <conio.h>
usingnamespace 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( 0, 4 ) << endl;
cout << "The next two characters are:\t\t" << substr( 4, 2 ) << endl;
cout << "Charters start at position 9 are:\t" << substr( 9, 5 ) << endl;
_getch();
return 0 ;
}
What's length() referring to? stateName? If so do stateName.length()
Also, find needs iterators find(stateName.begin(), stateName.end(), "is") and it will return an iterator to that location OR stateName.find("is) and it will return the position of the 'i'
same problem for substr, just add stateName.substr
All of this is because it is referring to a specific object and the way you have written it, it has no idea what length() is referring to since there is no way to figure where length() is since it is part of the strings class or to what it is referring as there aren't any arguments pointing to stateName (though that wouldn't be accepted as that's not how you do it :P)
Everything looks good minus line 10. It should look like this: cout << stateName << " has " << stateName.length( ) << " characters\n";
You had it right in your last post, why did you change it back? And the compiler that you're using should point you into the right direction as to what the issue is, mine said
Ah finally got it, , Thank You all for your input.
You know the reason I messed this code up was because I had made a mistake opening Visual, and instead of opening a .cpp file, I had opened and typed it all up on another format.
small and stupid mistake kept me changing the entire code aroung.
I think it all working ok now, but I'm sure I'll find something to change around in there still, which I'm sure will cause some other problem, which will make me have to ask for help again. . All part of a learning process