Include standard headers in customer headers

I am using VS2010 Pro.

I am busy with tutorial project and I am stuck on what I think is a really basic issue.

I have a main.cpp and I want to include a customer interface and implementation that I am writing. My interface needs to use some standard interfaces, but I keep getting erros when I include them.

To be more specific. I am writing a interface called strutils.h. Inside strutils, I need to declare some function prototypes that return a string value, so I have included the standard interface string (#include <string>) in the header. The compiler lists a whole host of errors when I try to compile.

I have added the strutils.h as a new item under "Header Files" in my project as well as the implementation file strutils.cpp under "Source Files"

Here is my strutils.h
----------------------------
#include <string.h>

string ConvertToLowerCase(string str1, string str2);
----------------------------

Here is my strutils.cpp
----------------------------
#include "strutils.h"


string ConvertToLowerCase(string str1, string str2)
{
}
----------------------------

Here is main.cpp
----------------------------
#include <iostream>
#include "strutils.h"

using namespace std;

void main ()
{

}
----------------------------

here are the errors:
----------------------------
Error 1 error C2146: syntax error : missing ';' before identifier 'ConvertToLowerCase' c:\users\rob\documents\2012\003.) hobbies & sport\003-003.) programming\003-003-004.) c++ projects\includes\strutils.h 3 1 CH-03-PE-04

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\rob\documents\2012\003.) hobbies & sport\003-003.) programming\003-003-004.) c++ projects\includes\strutils.h 3 1 CH-03-PE-04

Error 3 error C2146: syntax error : missing ')' before identifier 'str1' c:\users\rob\documents\2012\003.) hobbies & sport\003-003.) programming\003-003-004.) c++ projects\includes\strutils.h 3 1 CH-03-PE-04

Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\rob\documents\2012\003.) hobbies & sport\003-003.) programming\003-003-004.) c++ projects\includes\strutils.h 3 1 CH-03-PE-04

Error 5 error C2059: syntax error : ')' c:\users\rob\documents\2012\003.) hobbies & sport\003-003.) programming\003-003-004.) c++ projects\includes\strutils.h 3 1 CH-03-PE-04

I have set the project properties (VC++ Directories - Include Directories) to piint to the location where I have saved my strutils files.

I am sure this is something really simple that I am doing wrong, but being a newbie, I am not sure where to look.

Any help will be appreciated.

Thanks
Rob
Whatever tutorial you are using is (at best) very outdated.

A few things:

1) The header with string defined is <string>, not <string.h>

2) string is in the std namespace, so you need to do one of the following:

a) use std::string instead of string
or
b) put using namespace std; after your includes
or
c) put using std::string; after you includes


3) main() must return an int. It can't return a void. ie int main()
Last edited on
Hello Disch

Thanks so much for the reply. As it turns out the answer is so obvious. I have just forgotten to use the correct namespace. My apologies for posting such a dumb question.

I know it is a "little" dated, but I like the nostalgia :)

Thanks again for your help.

Regards
Rob
Topic archived. No new replies allowed.