所以,我是一名业余程序员,需要学习很多东西。但是我甚至不能得到一个简单的"如果那么"带字符串的语句。我的编译器没有返回错误,但程序不能按我的意愿工作。所以我写了这个小程序。我用一个字符串来定义变量任务。我希望用户输入他们的任务,程序就可以完成它。但是,它没有用。如果这是一个愚蠢的问题,请重定向我并禁止我的问题。 这不是写作"启动Chrome"或下一行。 (我打算用.exe运行的代码行替换这些行。) 这是我的源代码。
#include <iostream>
using namespace std;
int main()
{
string name;//Creates Name Variable
string task;//Declares task variable
cout << "Greetings, User!" << endl;
cout << "I am the OS 1.0!" << endl;
cout << "What is your name?" << endl; //Creates Intro Statement
cin>> name;
cin.ignore();
cout << "How may I help you today, " << name <<" ?" << endl; //Asks for task
cin>> task;
cin.ignore();
if (task == "Launch Chrome") { //If user types Launch Chrome...
cout << "Launching Google Chrome..." << endl; //...Write Launching...
cout << "Google Chrome Launched." << endl; // ...Then Write Launched.
}
return 0;
}
P.S如果有人知道运行.exe文件的代码,你能提供吗?我用&#34; cout Launching Chrome&#34;替换它。线。
在此先感谢您的帮助或任何重定向!
(我正在运行Codeblocks并且一直使用cprogramming.com作为指南。)