【问题标题】:Visual Studio C++, Identifier not foundVisual Studio C++,找不到标识符
【发布时间】:2016-04-08 16:46:25
【问题描述】:

这是我的代码!

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

我在这里得到了这个错误!

我想我可能需要下载一些额外的 Visual Studio C++ 相关目录,但还是请一些建议

【问题讨论】:

标签: c++


【解决方案1】:

clrscr() 不是标准函数。 Visual Studio 没有它。但是,MSDN 确实记录了如何使用system("cls") 或FillConsoleOutputCharacter() 和FillConsoleOutputAttribute() 来clear the screen。

对于cin/cout 错误,您需要在它们前面加上std:: 命名空间限定符,例如std::cin 和std::cout,或者在您的代码下面的代码中使用单独的using namespace std; 语句标头#include 语句。

试试这个:

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

或者:

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

【讨论】:

    【解决方案2】:

    现在你的 c++ 程序不知道什么是 clrscr();是..

    你必须定义那个函数。要定义它,请参阅@Remy Lebeau 的回答。

    一个快速的解决方案是简单地找出一堆空白,而不是创建一个清除屏幕的函数。

    所以你可以简单地把:

    std::cout << string(50, '\n');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 2019-12-31
      • 2017-01-03
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多