below is c++ code. And I am getting these warnings when compile
comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string::size_type’ {aka ‘long unsigned int’} [-Werror=sign-compare] 15 | for(int x=0; x<s.length();x++) ~^~~~~~~~~~~
different signedness means that I am comparing long unsigned int
which is 64 bits
to int
(which should be 32 bit
) I did not know.. that string.length
returns that type. So my question is how to write these simple instructions in c++
without any error showing when compiled with -Wall -Werror
I also get following error message. I supposed string
class is in namespace std
so the question is: when do we get this error and what that error tells. I think its saying that my program uses only namespace which is std
so its not required to do std:string s
to create a variable . this removes the error string s
without namespace. is this correct thinking or is there any other meaning too
f.cpp:7:1: error: label ‘std’ defined but not used [-Werror=unused-label] 7 | std:string s="hello";
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s="hello";
char c[s.length()-1];
s[1]='b';
char d='x';
s.push_back(d);
s+='x';
strcpy(c,s.c_str());
for(int x=0; x<s.length();x++)
{
cout<<c[x];
}
}