-4

I have three short files which I adapted from my project because they reproduce the errors I am having:

exp.cpp

#include <iostream>
using namespace std;

int main(){
    cout << "Hello world!" << endl;
}

parser.cpp

#include <cstring>
#include "parser.h"

parser.h

#ifndef PARSER_H_
#define PARSER_H_

#include <cstring>

class Parser{
public:
    Parser(std::string*);
    std::string* unprocessedInput;
};

#endif /* PARSER_H_ */

When I build the project, at the line,

Parser(std::string*)

I get the error message "expected ‘)’ before ‘*’ token" and at the line,

std::string* unprocessedInput;,

I get the error "‘string’ in namespace ‘std’ does not name a type".

When I use <string> instead of <cstring> in either parser.cpp or parser.h, the project builds. I want to understand why <cstring> is not working. I need to work with null-terminated strings in my project.

Note that I have searched extensively for this. In my research I got the idea of using std::string instead of a string in a header file.

  • 2
    You are aware of the problem, so what is the point of your question? Just include the correct headers for what you are doing. – JBentley Aug 16 '14 at 21:30
  • I want to work with null-terminated strings that's why I want to use . If I work with won't that mean I need to convert every string to cstring? – user3457382 Aug 16 '14 at 21:33

1 Answers1

4

Header <cstring> contains standard C declarations of C header <string.h> C++ header <string> contains the declaration of C++ standard class std::string (std::basic_string)

So <cstring> and <string> are different headers and contain different declarations.

According to the C++ Standard (relative to header <cstring>)

7 The contents are the same as the Standard C library header <string.h>, with the change to memchr() specified in 21.8.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335