I was trying to play with strings in a hangover program that I was writing and could not do such a thing Tried to work with them on a simple basis and I no longer have any luck.
As far as I have read online in context and why others have said this code:
#include & lt; Cstdio & gt; # Include & lt; Cstdlib & gt; # Include & lt; Cstring & gt; using namespace std; Int main (int argc, char ** argv) {string word = {"hello"}; Int length = Stellen (word); }
But I get this compiler error:
'String' is not declared in this area
And as a result, ' The word 'is also not declared in the scope.
Can anyone see what I am doing wrong? I am using the G ++ compiler on liberalization, if it does not matter, then it does not know which version is there.
You are confusing C and C ++
You have only added c libraries, while std :: string
comes from C ++ header string
. You must write:
#include & lt; String & gt;
To use it however, you may have to make another change again, such as not using strlen
.
You should learn from your C ++ book, not random posts on the Internet ( #lolirony )
C version
< Pre> #include & lt; String.h & gt; Int main (zero) {const char * word = "hello"; Const size_ length = strlen (word); // `size_t`` int` return is more than 0; }
C-like C ++ version
#include & lt; Cstring & gt; using namespace std; Int main () {const char * word = "hello"; Const size_ length = strlen (word); }
Symbolic C ++ version (recommended)
#include & lt; String & gt; Int main () {const std :: string word = "hello"; Const std :: size_t length = word.size (); }
Comments
Post a Comment