-2
#include "stdafx.h"
#include <iomanip>
#include <ostream>
#include <fstream>
using namespace std;

void FillArray(int x[ ], const int Size);
void PrintArray(int x[ ], const int Size);

int main() 
{
    const int SizeArray = 10;
    int A[SizeArray] = {0};
    FillArray (A, SizeArray);
    PrintAray (A, SizeArray);

    return 0;
}
void FillArray (int x[ ], const int Size)
{
    for( int i = 0; i < Size; i++);
    {
        cout << endl << "enter an integer"; //cout undeclared here
        cin >> x[i]; //cin and i undeclared here
    }

"cout"、"cin"、および "i" はすべてエラー " error C2065: 'cin' : undeclared identifier" を受け取ります。それらを修正する方法がわかりません。Main、fill array、print array の 3 つの関数が必要です。助けていただければ幸いです。

4

3 に答える 3

8
  1. の代わりに、と が含まれている<ostream>ため、 を含めたいと思う可能性が最も高いです。<iostream>cincout
  2. for ループの最後のセミコロンは、ループ内で実行されるステートメントを終了します。その結果、コードのブロックはそのループから分離されi、スコープ外になります。

より便利な質問/回答形式をサポートするために、今後はコードをスクリーンショットではなくテキストとして投稿してください。


ここに画像の説明を入力

于 2012-05-02T16:09:56.327 に答える
5

1) You have to include <iostream>, for the definitions of cin and cout.
2) You have a semicolon after your for loop, which will prevent it from repeating. It also makes the scope of i end, so you can't use it in the braces either.
3) Don't use using namespace without good reason.

4) Don't use pictures of code.
5) Always give full error messages. In Visual Studio that's in the "Output Window" not the "Error Window". For instance "identifier is unidentified" is not an error message.
6) Reduce your code to a SSCCE before posting, always. 95% of the time you'll find the problem yourself.

于 2012-05-02T16:12:27.723 に答える
3

std::coutstd::ciniostream で定義されているため、ファイルの先頭に追加する必要があり#include<iostream>ます。

于 2012-05-02T16:10:21.193 に答える