比较不同符号的整数表达式:正确使用;至于;处理字符串类型时循环 下面是C++代码。我在编译时收到这些警告
比较不同符号性的整数表达式:“int”和“std::uu cxx11::基本_字符串::大小_类型{aka'long unsigned int'}[-Werror=sign compare]比较不同符号的整数表达式:正确使用;至于;处理字符串类型时循环 下面是C++代码。我在编译时收到这些警告,c++,C++,比较不同符号性的整数表达式:“int”和“std::uu cxx11::基本_字符串::大小_类型{aka'long unsigned int'}[-Werror=sign compare] 15 | for(int x=0;xint是有符号的,length是无符号的。这很明显。使用size|t x=0。它是std::string,而不是std:string,:是一个不同于:的标记;它不是一行中的两个:标记。std:string s声明了一个标签std:(用于goto)声明字符串s var的地方
15 | for(int x=0;xint是有符号的,length是无符号的。这很明显。使用size|t x=0。它是
std::string
,而不是std:string
,:是一个不同于:
的标记;它不是一行中的两个:
标记。std:string s声明了一个标签std:(用于goto)声明字符串s var的地方。您需要std::string s。for(size\t x=0;…
是对您的问题的直接回答(除了上面建议的其他修复),但是您最好使用a和for(const auto&ch:s)std::cout
#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];
}
}