2016-04-08 100 views
-2

這是我的代碼!Visual Studio C++,找不到標識符

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

我在這裏得到這個錯誤!

This is the error I get

我想我可能需要下載一些額外的Visual Studio C++相關的目錄,但還是有些建議請

+1

嘗試'的std :: cin','的std :: cout',等等。 – songyuanyao

+0

http://stackoverflow.com/questions/930138/is-clrscr-a-function-in-c – Mohammad

+1

這麼多不好的事情。我建議你讓自己成爲一個[很好的C++書](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)來看看C++應該如何編碼。 – NathanOliver

回答

2

clrscr()不是一個標準功能。 Visual Studio沒有它。但是,MSDN確實記錄瞭如何使用system("cls")FillConsoleOutputCharacter()FillConsoleOutputAttribute()clear the screen

對於cin/cout錯誤,你需要用std::命名空間限定詞的前綴他們,如std::cinstd::cout,或在代碼中使用一個單獨的using namespace std;聲明的標題下#include語句。眼下

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

你的C++程序不知道是什麼clrscr();:

試試這個:

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

或者是..

您必須定義該功能。要定義它,請參閱@Remy Lebeau的答案。

一個快速的解決方案,而不是創建一個函數來清除屏幕是簡單地cout一堆空格。

所以在你的主,你可以簡單地說:

std::cout << string(50, '\n'); 
相關問題