#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
string word;
int j = 0;
cin >> word;
while(word[j]){
cout << "idk";
j++;
}
cout << "nope";
system("pause");
return 0;
}
這只是一個小試驗程序來測試這個循環。我正在處理的程序是關於從用戶確定的序列中取出元音和打印元音的。直到用戶輸入字符串纔會定義字符串。感謝您提前幫助您的人。字符串下標超出範圍。字符串大小是未知的和循環字符串,直到空
問題是該字符串不是像C字符串那樣的空終止字符數組。嘗試在超出字符串長度的位置調用[]運算符會導致報告的錯誤。對於以空字符結尾的字符數組,使用string :: c_str()方法 – Keith 2011-01-28 04:23:13