Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 99218

I am facing problem while iterating over a string vector

$
0
0

I was trying to make a program to convert numbers into words using the range-based loop for string vector.

    // conversion of numbers into word 
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    vector<string> words = {"one", "two", "three","four","five","six", 
    "seven", "eight", "nine"};

    for(int x:words){
      cin>>num; 
      if(num==words[x]) cout<<words[x]; 
    } 
    return 0;
}


// this program is showing error:
{
"message": "no suitable conversion function from\"std::__cxx11::string\" to \"int\" exists",

}

// If inside the 'for statement' I change int x to auto x this is working fine. I don't understand what difference does this makeS.


Viewing all articles
Browse latest Browse all 99218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>