How do I read arguments from the command line in C++?
I currently have this code:
int data_size = 0;
std::cout << "Please enter an integer value: ";
std::cin >> data_size;
std::cout << "The value you entered is " << data_size;
Main :
int main(int argc, char** argv) {
int data_size = 0;
std::cout << "Please enter an integer value: ";
std::cin >> data_size;
std::cout << "The value you entered is " << data_size;
// initialise the MPI library
MPI_Init(NULL, NULL);
// determine the world size
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// determine our rank in the world
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
std::cout << "rank " << world_rank << " size " << world_size << std::endl;
if (world_rank == 0){
coordinator(world_size);
}
else{
participant(world_rank, world_size);
}
MPI_Finalize();
return 0;
}
It works but it keeps asking me to enter an integer value 4 times then when I enter it a number it the command line freezes.
here is what i get in the command line
C:\Users\Roland\Documents\Visual Studio 2013\Projects\DistributedSystems\Debug>m
piexec -n 4 .\DistributedSystems.exe
Please enter an integer value:
Please enter an integer value:
Please enter an integer value:
Please enter an integer value: