This is based on GCC/G++ and usually on Ubuntu.
Here\'s my sample program I\'ve done:
#include
using namespace std;
int main()
{
Writing the string declaration as std:string also works fine. What's the difference.
There is no difference, unless you declare something else called string
. In your code, string
and std::string
refer to the same type. But avoid using namespace std
at all cost.
If I use this std::string within a class to declare a private variable, I get an error error: ‘std’ does not name a type. Example of this declaration:
You need to #include
in order to use std::string
. What is happening is that in your first code sample,
seems to be including
. You cannot rely on that. You must include
.