我已經從++教科書限定C-字符串一個C一個簡單的例子,並隨後循環至替代所有不屬於\ 0字符與X.錯誤與C-字符串工作
char ourString[5] = "Hi";
int index = 0;
while(ourString[index] != "\0")
{
ourString[index] = "X";
index++;
}
cout << ourString[] << endl;
然而元素當我編譯和運行我得到以下錯誤:
C:\Users\Ben\Dropbox\Learning Programming\C++\Strings\Strings.cpp||In function 'int main()':|
C:\Users\Ben\Dropbox\Learning Programming\C++\Strings\Strings.cpp|17|error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
C:\Users\Ben\Dropbox\Learning Programming\C++\Strings\Strings.cpp|19|error: invalid conversion from 'const char*' to 'char' [-fpermissive]|
C:\Users\Ben\Dropbox\Learning Programming\C++\Strings\Strings.cpp|23|error: expected primary-expression before ']' token|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|
我不明白爲什麼它不會讓我的問題(據我可以理解的錯誤),比較它們的字符元素,人物\ 0。我不認爲我在試圖比較一個整數的指針...