Errors not running

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.

This is the code

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
/*
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>

    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( 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 ;
}
Last edited on
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)
Last edited on
Edit: I've got conio blindness. I read as far as that and stopped :(
Last edited on
You are correct koltonaugust that was the same thing that I was told by another person as well.

Can you elaborate a little more on that, and how exactly you are typing the code?
Is this what you want me to do to the code

1
2
3
4
5
6
7
8
9
    cout  << stateName << " has " << stateName.length( ) << " characters\n";  

    cout  << "First occurance of word \"is\" is at position: " << find(stateName.begin(), stateName.end(), "is") <<  endl;

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

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

    cout << "Charters start at position 9 are:\t" << stateName.substr( 9, 5 ) <<  endl;
I'm using a 2010 version of it.
I suggest changing:
cout << "First occurance of word \"is\" is at position: " << find(stateName.begin(), stateName.end(), "is") << endl;

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

Moschops wrote:
Edit: I've got conio blindness. I read as far as that and stopped :(

As funny as this is, I use conio.h -.-
Last edited on
Ok so far I have gotten this far with it. I Still can't manage to get it running.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include  <iostream>
#include <conio.h>

using  namespace  std;

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

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

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

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

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

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

    _getch();
	return 0 ;
}



I was told to also take this

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


and add to look like this.

 
cout << "The first four characters are:\t\t" << stateName.substr( 0, 4 ).c_str() <<  endl;
Last edited on
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
Code Blocks wrote:
error: 'length' was not declared in this scope
Last edited on
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.

Thank You guys VERY MUCH ! ! !

Thank you Zach really do appreciate it
You're welcome, here to help, did you get your other program finished to your liking?

I don't like MSVS, and won't use it anymore. I have so many problems with it.
Last edited on
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
Topic archived. No new replies allowed.