Vector as an argument

Hi, I am new to C++. I am required to write a program that reads in 3 vectors plus other arguments and do some math on them.

This is how I want my command line expression to be

" >> createPoints.out -minP "(0.5 0.8 0.1)" -maxP "(1 2 5)" -V "(0 0.1 0.9)" -d 0.1

As you may see maxP, minP and V are vectors and d is a scalar. I tried to do this using argc, argv and found, stripping the values 0.5, 0.8 etc out avoiding the "(" and ")" rather cumbersome. I have read about the class Vector. How do I used that and also read these inputs and arguments? Thanks in advance for your responses.

If possible please provide me with a code snippet.

Thank You
Prapanj.
std::vector is just a container class, it won't help in parsing a string. You still have to parse the string. The best you can do is organise the code so its done in a convenient way,
stripping the values 0.5, 0.8 etc out avoiding the "(" and ")" rather cumbersome.

Here is a really simple example which doesn't take care of bad input:
1
2
3
4
5
6
7
8
//you need to #include <sstream>

stringstream ss ( argv[n] ); // assume argv[n] == "(0.5 0.8 0.1)";
char par;
ss >> par; // skip '('
double x,y,z;
ss >> x >> y >> z; // read the values
//use x, y, z as you wish 


C++ vector is more like a row matrix
Topic archived. No new replies allowed.