简体   繁体   中英

How to get the file_name in C++ if I executed my program with ./program_name<file_name

if I was executing the program like this: ./program_name<file_name How would I get the file_name in c++.

I tried to use argue[1] in the main and open file eg.

int main(int argc, char *argv[]){
    ifstream file;
    file.open(argv[1],ios::in);
}

its not opening

The < operator cat the file in input and you try in your code to get it from parameter. If you want to use input:

#include <string>

int main() {
    std::string data;
    // here you read all the file
    std::getline(std::cin, data);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM