if (input2 == "FDISK")
{
cin.ignore();
getline (cin, pingv);
if (pingv == "/mbr")
{cout <<"MBR suscsefully writen"<<endl;
menuinput();}
else
if (pingv.empty())
{
FDISK();}
}
help with blank in put that does not require to hit enter
I have only one question. Why does the below code require enter to be press twice?
this is what I am trying to achive
if fdisk is the input and you press enter goes to function if fdisk /[anything here]
will display another iteam
So I figured that if input 1 was fdisk and input 2 was blank that it would just go so how can I get it that I only have to hit enter once when just fdisk is entered and hit enter only once if fdisk /mbr is entered?
so another words I want the second input to be optinal and dont want to have to put anything in .
Unless there is another way to progream in switches for a command
[Edited by - kingpinzs on March 3, 2005 5:29:11 PM]
Can you please explain what you are trying to do here? I'm not getting it from your original post. I also recommend using better spacing in your code like this:
That way, it's much easier to line up the braces and check your logic.
if (input2 == "FDISK"){ cin.ignore(); getline (cin, pingv); if (pingv == "/mbr") { cout <<"MBR suscsefully writen"<<endl; menuinput(); } else if (pingv.empty()) { FDISK(); }}
That way, it's much easier to line up the braces and check your logic.
want I am trying to do is this.
promt c:>
input fdisk
gets a display
or
promt c:>
input fdisk /mbr
gets a display
now I could make it so each ine was it's own input but that is not what I want. I want to beable to add swiches to a command to do other things with the same command. you know like if you were in dos a you typed in format c: /s it would format the drive then add system files to it. But you could also just type in format c: and dont have to add the switch.
Hope that helps describing my issue
Thanks For the help so far
promt c:>
input fdisk
gets a display
or
promt c:>
input fdisk /mbr
gets a display
now I could make it so each ine was it's own input but that is not what I want. I want to beable to add swiches to a command to do other things with the same command. you know like if you were in dos a you typed in format c: /s it would format the drive then add system files to it. But you could also just type in format c: and dont have to add the switch.
Hope that helps describing my issue
Thanks For the help so far
Quote:Original post by kingpinz
now I could make it so each ine was it's own input but that is not what I want. I want to beable to add swiches to a command to do other things with the same command.
Going back to what smart_idiot said, you'd need to write a parser that read the input string, and then decided what to do. You probably should use strtok for this. However, the parsing itself is made caek by the fact that each command is separated by a space, but you could support other separation characters. You might also build a parsing tree, pre-sorted in some form to handle multiple switch commands.
#include <iostream>#include <string>// 'string' is the string you want to tokenize.// 'delimiters' contains the characters you have seperating the token.// string is replaced with the untokenized remainder.std::string getNextToken(std::string &string, const std::string &delimiters = " ") { std::string::size_type start = string.find_first_not_of(delimiters, 0), end = string.find_first_of(delimiters, start); if(start == std::string::npos) start = end = string.length(); else if(end == std::string::npos) end = string.length(); std::string result(string.substr(start, end-start)); string.erase(0, end); return result; }int main() { while(true) { std::string command, token; std::cout << "> "; std::cout.flush(); std::getline(std::cin, command); while(!(token = getNextToken(command)).empty()) std::cout << "token: '" << token << "'" << std::endl; } return 0; }
Quote:
MBR suscsefully writen
You're not going to fool anyone with spelling like that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement