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

The "cout", "cin", and "i" all get the error "error C2065: 'cin' : undeclared identifier". I have no idea how to fix them. I have to have three functions: Main, fill array, and print array. Help is appreciated.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
GmxTrey
  • 39
  • 1
  • 5
  • 8
    Do you write code in MSPaint? No? Then don't post a picture. – R. Martinho Fernandes May 02 '12 at 16:03
  • possible duplicate of [What is an 'undeclared identifier' error and how do I fix it?](http://stackoverflow.com/questions/22197030/what-is-an-undeclared-identifier-error-and-how-do-i-fix-it) – sashoalm Mar 05 '14 at 13:31

3 Answers3

8
  1. Instead of <ostream>, you most likely want to include <iostream>, as that includes cin and cout.
  2. The semi-colon at the end of your for loop ends the statement that executes in the loop. As a result, your block of code is separate from that loop, and i is no longer in scope.

In order to support a more useful Question/Answer format, in the future please post your code as text, not as a screenshot.


enter image description here

Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
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.

Mooing Duck
  • 64,318
  • 19
  • 100
  • 158
3

std::cout and std::cin are defined in iostream so you have to add #include<iostream> at the top of your file.

josefx
  • 15,506
  • 6
  • 38
  • 63