-3

I use Dev-C++ which has GCC 4.9.2 C++ compiler. I am confused on where and where not to use the following for declaring a string variable:

  1. #include <string> only
  2. #include <string.h> only
  3. using std::string only and no headers
  4. #include <cstring.h>

because everything compiles and run in devc++, I am unable to understand the concept behind all these

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 2
    `std::string`: _"Defined in header "_ see: http://en.cppreference.com/w/cpp/string/basic_string Also headers: http://en.cppreference.com/w/cpp/header – Richard Critten Jun 11 '17 at 11:00

1 Answers1

2

To use std::string always use #include <string>.

The other header files you mentioned have nothing to do with std::string.

The std namespace scope can be omitted if you have an appropriate using statement like

using std::string;

or

using namespace std;

(the latter isn't recommended in real code for various reasons)

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190