简体   繁体   English

Cygwin“使用:找不到命令”用于C ++程序

[英]Cygwin “using: command not found” for C++ program

Hoping to free myself from Eclipse and not wanting to keep using the online cpp.sh, I wrote a small program in Cygwin in nano and tried to run it. 希望从Eclipse中解放自己,又不想继续使用在线cpp.sh,我在Cygwin中用nano编写了一个小程序,然后尝试运行它。 The code is included for clarity. 为了清楚起见,包含了该代码。

#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;
}

Trying to run it returns a series of errors, as seen in the picture . 试图运行,将会返回一系列错误,如看到的画面 Right now, I'm trying to understand why "using" is not recognized. 现在,我试图理解为什么无法识别“使用”。 Checking Google found many similar complaints, but never about the command "using," probably because "using" is a common enough word to be using in a different context. 检查谷歌发现了许多类似的投诉,但从来没有想过命令“使用”,大概是因为“使用”是一个非常普通的字可以在不同的上下文。

You can't run source code directly. 您不能直接运行源代码。 You must compile it first. 您必须先编译它。

Well, a lot of g++ compile errors are because you have 好吧,许多g ++编译错误是因为

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

when you probably meant 当你可能是说

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

with one more quotation mark 再加上一个引号

As soon as you insert the " into line 14 it will compile and run, but the last portion will not complete. 将“”插入第14行后,它将编译并运行,但最后一部分将不完整。

I would also create another string near mystr, and use it for getline() . 我还将在mystr附近创建另一个字符串,并将其用于getline() Reusing mystr faults when I compile it. 在编译时重用mystr错误。 int main() { int i; string mystr; string team;

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

After changing and compiling, I get: Enter number: 3 You entered: 3 and its double: 6. Name: Aaron Hello Aaron. Team? Meow Go Meow! 更改和编译后,我得到: Enter number: 3 You entered: 3 and its double: 6. Name: Aaron Hello Aaron. Team? Meow Go Meow! Enter number: 3 You entered: 3 and its double: 6. Name: Aaron Hello Aaron. Team? Meow Go Meow!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM