【发布时间】:2018-04-15 16:56:17
【问题描述】:
我正在制作一个命令行程序,我想知道如何获取句子的不同部分,所以假设有人输入 cd Windows/Cursors,它会检测(使用 if 语句)他们输入了 cd,然后(在同一个 if 语句中)它将选择句子的其余部分,并将其设置为目录。这是我的代码:
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
while (1)
{
string directory = "C:/";
string promptInput;
string afterPrint;
string prompt = "| " + directory + " |> ";
cout << prompt;
cin >> promptInput;
if (promptInput == "")
{
}
else if (promptInput == "h:/")
{
directory = "H:/";
}
if (promptInput != "") {
cout << " " << afterPrint << "\n";
}
}
return 0;
}
我还没有尝试过任何东西,所以我愿意接受建议。
我们将不胜感激。
-迦勒辛
【问题讨论】:
-
不相关:如果您使用的是 Visual Studio,并且
#include "stdafx.h"建议这样做,请将#include "stdafx.h"放在文件的第一部分。上面的所有内容都将被忽略。更多信息:stackoverflow.com/questions/2976035/purpose-of-stdafx-h。为什么人们忍受这个蓝精灵:stackoverflow.com/questions/4726155/…
标签: c++ string shell command-line command