c++ - expression must have integral or unscoped enum type, with string vectors -


so trying make program move files of type, downloads folder folder supposed belong.

i have been researching awhile , have come with:

#include <iostream> #include <fstream> #include <string> #include <windows.h> #include <vector> #include <stdio.h>  using namespace std;  vector<string> getfilenamesindirectory(string directory) {      vector<string> files;     handle hfind;     win32_find_data data;      hfind = findfirstfile(directory.c_str(), &data);     if (hfind != invalid_handle_value) {         {             files.push_back(data.cfilename);         } while (findnextfile(hfind, &data));         findclose(hfind);     }     return files; }  int main() {      string *paths = new string[2];     string line;     ifstream pathfile("paths.txt");     int = 0;     vector<string> rsfiles;     string currentfile;     int movecheck;      if (pathfile.is_open()) {         while (getline(pathfile, line)) {             paths[i] = line.substr(line.find_first_of(" ")+1);             i++;         }         pathfile.close();     }     else {         cout << "unable open file" << endl;         return 0;     }      rsfiles = getfilenamesindirectory(paths[0]+"*.psarc");      (int j = 0; j < rsfiles.size(); j++) {          currentfile = rsfiles[j];          movecheck = rename(paths[0].c_str() + currentfile.c_str(), paths[1].c_str() + currentfile.c_str());      }      system("pause");     return 0; } 

so when go move files in rename(), error 'currentfile' saying "expression must have integral or unscoped enum type". assuming because can't index way am, or along lines.

i new c++, have other coding experience, , makes sense me.

also, know have taken code other sources, not intend on selling or making public, myself , own personal use.

you need change way concatenate 2 strings, to:

movecheck = rename((paths[0] + currentfile).c_str(), (paths[1] + currentfile).c_str()); 

c_str() taking pointer buffer of characters inside each string, adding 2 pointers doesn't make sense. instead, need add 2 strings, , grab data buffer concatenated string.


and way write this, @martin bonner , @nicky

std::string oldpath = paths[0] + currentfile;  std::string newpath = paths[1] + currentfile;  movecheck = rename(oldpath.c_str(), newpath.c_str()); 

Comments