Home > Enterprise >  Cannot add constant to vector
Cannot add constant to vector

Time:10-10

I tried to add path to my vector but it's defined by constant. What do I need to do to fit the data from entry.path() to my vector.

#include <iostream>
#include <string>
#include <vector>
#include <filesystem>

namespace fs = std::filesystem;

int main () {
    std::vector<std::string> sourceContent;
    std::string replica = "replica";
    std::string source = "source";
    for (auto & entry : fs::recursive_directory_iterator(source)) {
        sourceContent.push_back(entry.path());
        std::cout << entry.path() << std::endl;
        }
}

CodePudding user response:

Yout need you to use the string() member function:

sourceContent.push_back(entry.path().string());

Another option would be to store actual paths in the vector instead:

std::vector<std::filesystem::path> sourceContent;
  •  Tags:  
  • c
  • Related