我写了这段代码但是vs给了我一个关于getch()的错误。我的编码有什么问题?????在此之前,我在我的代码中使用了_getch()语句并且没有任何问题,但知道它给了我一个错误。什么问题????
错误:第16行错误错误C2220:警告被视为错误 - 没有'对象'文件生成
/***********************************************************\
* This program counts word and characters of a paragraph *
* Write by : saeid asaadian *
* Create date : 11 - 7 - 2015 *
* Version : 1.0 *
\***********************************************************/
#include <iostream>
#include "conio.h"
using namespace std;
int main()
{
int char_counter=0, word_counter=0;
char ch = 0;
cout << "Please Type your paragraph (press ENTER for end) : \n";
cin >> ch;
while ((ch = _getche()) != '\n')
{
char_counter++;
if (ch == ' ')
word_counter++;
} // end of while loop
cout << "\nnumber of characters is :" << char_counter << "\nnumber of word is :" << word_counter << endl;
_getche();
return 0;
}
答案 0 :(得分:1)
您应该将getche()更改为getchar(),因为getche是过时的函数。
一切正常。 ;)
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int char_counter = 0, word_counter = 0;
char ch = 0;
cout << "Please Type your paragraph (press ENTER for end) : \n";
cin >> ch;
while ((ch = getchar()) != '\n')
{
char_counter++;
if (ch == ' ')
word_counter++;
} // end of while loop
cout << "\nnumber of characters is :" << char_counter << "\nnumber of word is :" << word_counter << endl;
getchar();
return 0;
}
答案 1 :(得分:0)
将标题文件#include "conio.h"
更改为#include <conio.h>
此头文件中定义了getch()
函数。