-2

This is my code!

#include "stdafx.h"
#include<iostream>
#include<conio.h>
void main()
{
clrscr();
int no;
cout<<"Enter a number";
cin>>no;
getch();
}

and I get this error here!

This is the error I get

I think I might have to download some extra visual studio c++ related directories, but still some suggestions please

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Omkar Patil
  • 21
  • 1
  • 1

2 Answers2

2

clrscr() is not a standard function. Visual Studio does not have it. However, MSDN does document how to clear the screen using system("cls"), or FillConsoleOutputCharacter() and FillConsoleOutputAttribute().

As for the cin/cout errors, you need to prefix them with the std:: namespace qualifier, eg std::cin and std::cout, or use a separate using namespace std; statement in your code below the header #include statements.

Try this:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <conio.h>

void clrscr()
{
    std::system("cls");
}

int main()
{
    clrscr();
    int no;
    std::cout << "Enter a number";
    std::cin >> no;
    getch();
    return 0;
}

Or:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <conio.h>

using namespace std;

void clrscr()
{
    std::system("cls");
}

int main()
{
    clrscr();
    int no;
    cout << "Enter a number";
    cin >> no;
    getch();
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

Right now your c++ program doesn't know what clrscr(); is..

you have to define that function. To define it, see @Remy Lebeau's answer.

One quick solution instead of creating a function to clear out the screen is to simply cout a bunch of blank spaces.

so in your main you can simply put :

std::cout << string(50, '\n');
psj01
  • 3,075
  • 6
  • 32
  • 63