How do I convert vector of strings into vector of integers in C++?

前端 未结 7 2049
甜味超标
甜味超标 2021-01-23 01:10

I have a vector of strings. Need help figuring out how to convert it into vector of integers in order to be able to work with it arithmetically. Thanks!

#include         


        
7条回答
  •  -上瘾入骨i
    2021-01-23 01:25

    Here is the working version made up using the above comments.

    #include 
    #include 
    #include 
    #include 
    
    using namespace std;
    
    int main(int argc, char* argv[]) {
    
        vector vectorOfStrings;
        vectorOfStrings.push_back("1");
        vectorOfStrings.push_back("2");
        vectorOfStrings.push_back("3");
    
        for (int i=0; i vectorOfIntegers;
        int x;
        for (int i=0; i> x;
            vectorOfIntegers.push_back(x);
        }
    
        int sum = 0;
        for (int i=0; i

提交回复
热议问题