1

I read lines from a text file and would like to repeated delimiters as \t\t. Normally I have between delimiters a parameter but for readability reasons it is sometimes nice to use strings as \t\t\t in order to line out text sequences.

I wrote a class in my main.cpp that worked well. Because I would like to keep my main.cpp as compact possible, I tried to create a class file with header file. I did the forward declaration in the header file, and pasted the working class member in the class.cpp file.

The Class uses string type variables that are declared in the class.cpp. When compiling the compiler gives me an error saying that "string does not name a type". I guess there is something wrong with the moment I do the include of the string.h header.

It is included in the Main.cpp file. Should I include it also in the header file for the class or in the class.cpp file. I understood from previous exchanges that including libraries everywhere should be avoided.

Thanks in advance,

Stefan

1
  • Sorry, I forgot to define strings as std::string, what seemed to solve the problem, but when the last string type definition was modified to std::string the compiler gave me again errors of the same type. Commented Jul 31, 2011 at 12:08

3 Answers 3

1

If you want to use C++ std::string you should include the <string> header.

The similarly named <string.h> is for C language string functions.

Sign up to request clarification or add additional context in comments.

Comments

1

Header files should be self-contained, i.e. include all the things they require for themselves (like types they refer to). To prevent bad performance and other issues, so-called include guards prevent repeated inclusion.

Comments

1

You need to include the .h file in all other files (.h or .cpp) that use the types/functions you declare in the header.

class.cpp should include class.h. main.cpp should include class.h if it uses your string class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.