Cygwin "using: command not found" 用于 C++ 程序

Cygwin "using: command not found" for C++ program

希望从 Eclipse 中解脱出来,不想继续使用在线 cpp.sh,我在 nano 中用 Cygwin 编写了一个小程序并尝试 运行 它。为清楚起见,包含代码。

#include <iostream>
#include <string>

using namespace std;

int main()
{
  int i;
  string mystr;

  cout << "Enter number: ";
  cin >> i;
  cout << "You entered: " << i;
  cout << " and its double: << i*2 << ".\n";
  cin.ignore();
  cout << "Name: ";
  getline(cin, mystr);
  cout << "Hello " << mystr << ".\n";
  cout << "Team? ";
  getline(cin, mystr);
  cout << "Go " << mystr << "! \n";
  return 0;
}

尝试运行它returns一系列错误,如picture中所见。现在,我正在尝试理解为什么无法识别 "using"。检查 Google 发现了许多类似的投诉,但从来没有关于命令 "using," 的投诉可能是因为 "using" 是一个足够常见的词,可以 在不同的上下文中使用 .

您不能 运行 直接获取源代码。你必须先编译它。

嗯,很多g++编译错误都是因为你有

cout << " and its double: << i*2 << ".\n";

当你的意思可能是

cout << " and its double: " << i*2 << ".\n";

多一个引号

只要将 " 插入第 14 行,它就会编译 运行,但最后一部分不会完成。

我还会在 mystr 附近创建另一个字符串,并将其用于 getline()。编译时重用 mystr 错误。 int main() { int i; string mystr; string team;

`getline(cin, team);
cout << "Go " << team << "! \n";`

修改编译后得到: Enter number: 3 You entered: 3 and its double: 6. Name: Aaron Hello Aaron. Team? Meow Go Meow!