Hey Guys! I am writing a program on C++ with linux that will require the user to use the program by typing:
./contactadd 12 June 2010 Jessica Daniels Description
It is a contact saver, I think I have the birthday (eg. 12 June 2010) saved and sorted, however I want the name and description to be converted to one string or something like that because I don't know how many words will make up the description.
as you can see the user can only input one word for the description and name.
How could I make it so the user can input as much words for the description as she/he wants?
#include <iostream>
#include <string>
int main (int argc, char** argv)
{
std::string line = "";
for (int i = 1; i < argc; i++)
{
line += argv [i];
}
// Just for testing
std::cout << "Output: " << line << "\n";
return 0;
}
You could require the user to quote the various fields
./contactadd "12 June 2010" "Jessica Daniels" "Description of some or other very young person"
or
./contactadd "21 June 1982" "William Arthur Philip Louis Windsor" "Second in the line of succession to the throne"
this will arrive as arg[1] - arg[3]
Or you could require some sort of delimiter between the fields.
./contactadd 12 June 2010 + Jessica Daniels + Description of some or other very young person + extra info (only first 2 pluses are special!)
(this choice of delimiter might cause problems for B.S.
./contactadd 30 December 1950 + Bjarne C++ Stroustrup + C++ is his middle name!
)
You might also consider implementing a "beginner" mode, where you start the app with no command line params and it prompts for each field and then confirms before committing the data.