开发者

Problem with Class for processing of strings

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜