标签:add style 输入 日期 result upper namespace ima c++
一、预处理指令
问题:输入一些WORD,判断有没有首字母大写的两个相同的词
1 #include<iostream> 2 #include<string> 3 4 using namespace std; 5 6 int main() 7 { 8 string currWord, preWord; 9 cout << "Enter some words:(ctrl+z to end)" << endl; 10 while (cin >> currWord) 11 { 12 #ifndef NDEBUG 13 cout << endl << "调试:" << currWord << endl; //这是调试用的 14 #endif 15 if (!isupper(currWord[0])) 16 continue; 17 if (currWord == preWord) 18 break; 19 else preWord = currWord; 20 } 21 if (currWord == preWord&&!currWord.empty()) 22 { 23 cout << "The repeated word:" << currWord << endl; 24 } 25 else 26 cout << "没有重复的!" << endl; 27 system("pause"); 28 }
关闭预处理:
解决资源方案--demo--右键“属性”--c++--命令行----附加选项:/DNDEBUG
结果:
二、预处理常量
1 #include<iostream> 2 #include<string> 3 4 using namespace std; 5 6 int main() 7 { 8 cout << "文件:" << __FILE__ << endl<<"行:" << __LINE__ << endl<<"日期:" << __DATE__ << endl<<"时间:" << __TIME__ << endl; 9 system("pause"); 10 }
三、assert断言
1 #include<iostream> 2 #include<assert.h> 3 4 using namespace std; 5 6 int add(int x, int y) 7 { 8 return x * y; 9 } 10 int main() 11 { 12 int result; 13 result = add(1, 2); 14 assert(result == 3); 15 cout << result << endl; 16 system("pause"); 17 }
断言也用来调试,与预定义一样,受附加选项/DNDEBUG控制
标签:add style 输入 日期 result upper namespace ima c++
原文地址:https://www.cnblogs.com/dameidi/p/9284160.html