请帮我纠正这个错误。 [错误]'clrscr'未在此范围内声明(它从外部文件中选择问题和答案) [英] please help me correct this error. [Error] 'clrscr' was not declared in this scope (it picks questions and answers from an external file)

查看:678
本文介绍了请帮我纠正这个错误。 [错误]'clrscr'未在此范围内声明(它从外部文件中选择问题和答案)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <fstream>
#include <time.h>
using namespace std;

string questions[50];
string str;

class contest
{

private:
  int roll;
  float x;
  char name[50];
  char s[100],ans;

 public:
 contest()
 { x=0; }
 void init();
 void define();
 void display();
 };
 void  contest :: define()

 {
ifstream in;
  char a;
  int i=0;

  in.open("questions.txt");
  while(in.eof()==0)
 {
 in.getline(s,100);
 cout<<endl<<s;
if(i==5)
{
in.get(a);
cout<<"\nans:";
 cin>>ans;
i=-1;
if(ans==a)
   {
   x=x+5;
   cout<<" *Your ans  correct.\n";
   }
 else
   {
   if(x>0)
    x=x-2.5;
   cout<<" # Wrong ans.\n";
   }
 }
  i++;
  }
 in.close();
 }
  void contest :: init()
   {
 cout<<"\t\t\t   Student Name:";
 cin>>name;
 cout<<"\t\t\t   Index Number:";
 cin>>roll;
   }
 void contest :: display()
   {
 cout<<"\n **Result:\n";
 cout<<"\t"<<name<<" you got total "<<x<<" marks, out of 50.\n";
   }

 int main()
{
  clrscr();
  contest r;
  cout<<"      \t\t\t     QUIZ    \t      Total Marks:50\n\n";
  r.init();
  cout<<"\t*5 marks per Ques(half negative marking for wrong ans)";
   L:
  cout<<"\n\n\tselect your choice:\n"
    <<"\n\tTo start Quiz Press 1"
    <<"\n\tTo quit Press 0        :";
   int c;
   cin>>c;
   switch(c)
   {
   case 1:
    r.define();
    r.display();
    break;
   case 0:
    exit(1);
   default:
    cout<<"invalid choice!";
    goto L;
   }
   getch();
   }

推荐答案

clrscr 是Borland TurboC ++非标准函数,在其他编译器中不存在。

在你的代码中,我只是删除了调用(因为你只在主函数的顶部使用它一次)和忽略清洁屏幕的lask是叶子,但我找到了一种方法: http://stackoverflow.com/questions/930138/is-clrscr-a-function-in-c [ ^ ]应该有效。

clrscr is a Borland TurboC++ non-standard function, and isn't present in other compilers.
In your code, I would just remove the call (since you only use it the once at the top of the Main function) and ignore the lask of "clean screen" is leaves, but there is a method I found here: http://stackoverflow.com/questions/930138/is-clrscr-a-function-in-c[^] which should work.
// somewhere in the program
#DEFINE WINDOWS 1

void console_clear_screen() {
  #ifdef WINDOWS
  system("cls");
  #endif
  #ifdef LINUX
  system("clear");
  #endif
}


#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#define WINDOWS 1

void clrscr() {
  #ifdef WINDOWS
  system("cls");
  #endif
  #ifdef LINUX
  system("clear");
  #endif
}

int main(){
    int a = pow(3,2);
    clrscr();
    printf("\nMath Power Function :: %d ",a);
    getch();
    return 0;
}


这篇关于请帮我纠正这个错误。 [错误]'clrscr'未在此范围内声明(它从外部文件中选择问题和答案)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆