cstring_iter.cpp
来自「斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》」· C++ 代码 · 共 33 行
CPP
33 行
#include <iostream>#include <cstring>#include <cctype>using namespace std;int main(){ char word[] = "hello"; // Random-access iteration for ( unsigned int i = 0; i < strlen(word); i++ ) word[i] = toupper( word[i] ); cout << word << endl; // The same iteration, using a pointer, // is actually more efficient, because // incrementing is a cheaper operation // than the regular addition carried out // by the compiler to compute the address // of word[i] char *cp = word; while ( *cp != '\0' ) *cp++ = tolower( *cp ); for ( char *cp = word; *cp != '\0'; cp++ ) *cp = tolower( *cp ); cout << word << endl;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?