开发者

Command Line Arguments in XCode

开发者 https://www.devze.com 2022-12-16 02:39 出处:网络
I\'m trying to pass arguments in XCode and understand you need to add them from the Args tab, using the Get Info button, in the Executables of the Groups and Files pane.I\'m trying to see if I can get

I'm trying to pass arguments in XCode and understand you need to add them from the Args tab, using the Get Info button, in the Executables of the Groups and Files pane. I'm trying to see if I can get it to work, but am having some difficulty. My program is simply:

#include <iostream>
#include <ostream>
using namespace std;

int main(int argc, char *argv[]) {

    for (int i = 0; i < argc; i++) {
        cout << argv[i];
    }

    return 0;

}

And in the Args tab, I have the number 2 and then in anot开发者_Go百科her line the number 1. I do not get any output when I run the program. What am I doing wrong? Thanks!


Your code works fine and it displays the arguments. You may want to print a new line after each argument to make the output more readable:

cout << argv[i] << "\n";

Output is visible in the console (use Command+Shift+R to bring up the console).

0

精彩评论

暂无评论...
验证码 换一张
取 消