在C++中使用main之后添加其他函数时未声明的标识符?

Gmx*_*rey -2 c++ arrays const function

#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
    }
Run Code Online (Sandbox Code Playgroud)

"cout","cin"和"i"都会收到错误" error C2065: 'cin' : undeclared identifier".我不知道如何修复它们.我必须有三个功能:Main,fill array和print array.感谢帮助.

Sam*_*aan 8

  1. 而不是<ostream>,你很可能想要包括<iostream>,因为它包括cincout.
  2. for循环结束时的分号结束循环中执行的语句.因此,您的代码块与该循环分开,并且i不再在范围内.

为了支持更有用的问答形式,将来请将您的代码发布为文本,而不是截图.


在此输入图像描述


Moo*_*uck 5

1)你要include <iostream>,为的定义cincout.
2)你的for循环后你有一个分号,这将防止它重复.它也使得i结束的范围,所以你也不能在大括号中使用它.
3)using namespace没有充分理由不要使用.

4)不要使用代码图片.
5)始终提供完整的错误消息.在Visual Studio中,位于"输出窗口"而不是"错误窗口".例如,"标识符未识别"不是错误消息.
6)始终在发布之前将代码减少到SSCCE.95%的情况下你会自己发现问题.