-4

Please note, that I did add a header file strutils.h, also I copied this file in the project. strutils.cpp was added to the Source Files and was also copied into the Project folder.

**The Error I receive is as follows: error C2039: 'ToLower' : is not a member of 'std::basic_string<_Elem,_Traits,_Alloc>' **

I started the code following the book Computer Science Tapestry by Astrachan, I did check the book several times, but no result on my part. (The library strutils does include ToLower() function)

I feel that I am missing something very simple.

Below is my code.

    #ifndef _STRUTILS_H
    #define _STRUTILS_H

    #include <iostream>
    #include <string>
    #include "strutils.h"
    using namespace std;

    int main()
    {
         string boot = "Drimmnal";
         boot.ToLower();

         cin.ignore();
         cin.get();
         return 0;
    }

     #endif 
GunCode
  • 3
  • 1
  • 5
  • 1
    Please learn C++ systematically from a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), or badness like this code will keep haunting you and your colleagues. – Baum mit Augen Jul 19 '15 at 20:33
  • 1
    The message means that `ToLower` isn't a member of `std::string`, of which `boot` is an instance. Read [a good reference](http://en.cppreference.com/w/cpp/string/basic_string). – juanchopanza Jul 19 '15 at 20:34
  • 2
    @GunCode: Read your book again, the signature for that function is `void ToLower(string & s);`. It's not a `std::string` member function and it doesn't take two numeric parameters. – Blastfurnace Jul 19 '15 at 20:44
  • @Blastfurnace The two Parameters are a result of series of debugging on my part. Removing them does not change anything. – GunCode Jul 19 '15 at 20:47

1 Answers1

2

The function you are trying to use is not a member function of the Standard Library std::string class so you can't call it by saying boot.ToLower(). That syntax is reserved for member functions.

This function is provided in the support materials for your book. It has a signature of void ToLower(string & s);. It's a free function that takes a std::string by reference and, I assume, changes the string in place. You'll want to call it like any other free function and pass it a std::string variable.

Change:

boot.ToLower();

To:

ToLower(boot);

In addition, you want to remove the following lines from your source code:

#ifndef _STRUTILS_H
#define _STRUTILS_H

and

#endif

These lines are include guards from the strutils.h file and I'm not sure why they are in your source file.

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70