+ 1
ERROR:Assigning value for string using for loop
int main() { string match; string hello="hello"; int i=hello.size(); for(int j=0;j<i;j++){ match[j]=hello[j]; } cout<<match; }//it's showing no output
1 Answer
+ 1
int main() {
string match = "";
string hello = "hello";
int i = hello.size();
for(int j =0;j<i;j++) {
match = match + hello[j];
}
std::cout<<match;
std::cout<<hello;
}
you cannot use match[j] because match is not array, and you are not fill it with any string, maybe that is :D, the code is tested , and its work.