我遇到轉換問題。我不能使用字符串在這個節目,所以我不得不使用char
的 - 我得到的錯誤:不能將Const Char [21]轉換爲Char?
error C2664: 'printText' : cannot convert parameter 1 from 'const char [21]' to 'char'
1> There is no context in which this conversion is possible
我試圖將其轉換爲一個常量指針:
void printText(const char* text[100] = "notextgiven"...
,但它不「 t似乎有所幫助,給了我更多的錯誤。
我的計劃:
#include <iostream>
using namespace std;
void printText(char, char, int);
int main(){
printText("I hear and I forget.", "*", 15);
}
void printText(char text[100] = "notextgiven", char symbol = ' ', int repeat = 10){
int temp = 0;
while(temp < repeat){
cout << symbol;
temp++;
}
cout << text;
temp = 0;
while(temp < repeat){
cout << symbol << endl;
temp++
}
}
此外,'「*」''應該是''*''而不是... – 2012-08-25 22:21:43
你知道字符(字符)和字符串之間有什麼區別嗎? – jalf
@Derp不要更新代碼來回答你的問題。保持原樣。如果其他人出現這個問題,並且發現代碼中沒有錯誤,但是看到你正在尋求幫助解決一些不存在的問題?他們會感到困惑。下次,請不要更改您的問題或您的代碼。您應該這樣做的唯一原因是爲了清晰起見。 – 0x499602D2