简体   繁体   中英

How can I run c++ program with .txt file as an arguement on mac terminal?

I am trying to run a c++ program with a txt file as a command line arguement. I used chmod u+rwx filename to change the access and g++ to compile and./ to run. I am keep getting an error message saying "zsh: permission denied: ./ ". I can make unix executable file using g++, bu when I run the progrma with./ and txt file ans an arguement, it returns an error message above.
what my terminal looks like

-Air ~ % cd /Users/klee/Desktop/pa3+ect/cs1/page-link            
-Air page-link % g++ page.cpp page_rank.cpp web.cpp -o rank1
-Air page-link % ./ rank1
zsh: permission denied: ./
-Air page-link %

U can use the standard argument to get the file path and then parse the file text into a variable.

int main(int argc, char** argv) 
{ 
cout << "You have entered " << argc 
     << " arguments:" << "\n"; 

for (int i = 0; i < argc; ++i) 
    cout << argv[i] << "\n"; 

return 0; 
} 

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