簡體   English   中英

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

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

希望從Eclipse中解放自己,又不想繼續使用在線cpp.sh,我在Cygwin中用nano編寫了一個小程序,然后嘗試運行它。 為了清楚起見,包含了該代碼。

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

試圖運行,將會返回一系列錯誤,如看到的畫面 現在,我試圖理解為什么無法識別“使用”。 檢查谷歌發現了許多類似的投訴,但從來沒有想過命令“使用”,大概是因為“使用”是一個非常普通的字可以在不同的上下文。

您不能直接運行源代碼。 您必須先編譯它。

好吧,許多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! 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