+ 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

25th Nov 2017, 5:40 AM
I'm_Groot
I'm_Groot - avatar
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.
25th Nov 2017, 9:55 AM
Momo Belia
Momo Belia - avatar