Search code examples
c++xcodexcode4arguments

how to get input from console in Xcode 4 in C++


i want to run project in xcode but i can not get input from console i have checked websites but i can't get it.

#include <iostream>
#include <stdio.h>
using namespace std;
int main (int argc, const char * argv[])
{

cout<<"\n"<<argc<<"\n";  

i am getting the ouput as 1 but i don't know how to get input from the console

output that i am getting is

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000 [Switching to process 8492 thread 0x0]

1 Program ended with exit code: 0


Solution

  • argc is not "input from the console", it's the number of arguments passed to your program on the command line (and those arguments are contained in argv).

    If you want to get input from the console, you would need to read from standard in (std::cin)

    See: http://www.cplusplus.com/doc/tutorial/basic_io/