C++:清除Dos窗口上的内容,让程序可以循环执行
C++:清除Dos窗口上的内容,让程序可以循环执行 当这个程序运行一次之后,窗口上就会出现很多信息,现在我想在不重新运行程序 的情况下清除上一次运行后在Dos窗口上出现的信息,然后接着做下一次的测试,请问代码该怎么改写?高手赐教!!!谢谢 代码: // Program 6.7 Accessing characters in a string #include <iostream> #include <string> #include <cctype> #include <iomanip> using std::cout; using std::cin; using std::endl; using std::string; int main() { string text; // Stores the input cout << endl <<"This program is used to count the number of occurrence of each digit in your input. " << endl<< endl<<"Please enter a line of text:" << endl<< endl<< endl; // Read a line of characters including spaces std::getline(cin, text); cout<< endl<< endl<< endl << "You entered:" << endl << endl<< endl<<text << endl<< endl; int count[10]= {0}; for(int i = 0 ; i < text.length() ; i++) if(std::isdigit(text[i])) switch(text[i]) { case '0': count[0]++; break; case '1': count[1]++; break; case '2': count[2]++; break; case '3': count[3]++; break; case '4': count[4]++; break; case '5': count[5]++; break; case '6': count[6]++; break; case '7': count[7]++; break; case '8': count[8]++; break; case '9': count[9]++; break; } int sum=0; for(int i=0;i<10;i++) sum+=count[i]; cout<< endl<< "Your input contained "<<sum<<" digits."<< endl<< endl <<"Below is a frequency table listing the different digits in ascending order with their frequencies and their relative frequencies." <<"\n"<<"\n"<<"\n"<<"\n"; cout<<"\t"<<"Digit"<<"\t\t"<<"Frequency"<<"\t"<<"Relative Frequency"<<"\n"<<"\n" ; for(int i=0;i<10;i++) cout<< " "<<"\t" <<i <<"\t\t"<< count[i] << "\t\t"<< count[i]/static_cast<double>(sum) << endl; cout<< endl<< endl; return 0; }
system("cls"); CMD清屏命令
问:挺简单的一C函数,不过我是初学者,暂时还不会写,请好心人多多帮忙!
答:int mystrlen(char *str) { int n = 0; while (*str) { n++; str++;} return n; } voi...详情>>