我主要有一個函數(INT,字符串):如何在函數中傳遞字符串?
string word("HELLO");
int x = 0;
char choice;
swap(x, word);
我想,沒有成功,進入下面的函數:
void swap(int, string) {
int x = 0;
string word = "HELLO";
cout << "Would you like to change a letter? Please enter the letter
position. " << endl;
cin >> x;
if (x == 1) {
cout << "What do you want to change it to?" << endl;
cin >> word[0];
我不斷收到此錯誤:
錯誤C2664 '無效化std :: swap(STD :: exception_ptr &,性病:: exception_ptr &)擲()':無法從 '詮釋' 轉換參數1 '的std :: exception_ptr &'
什麼給了?
從'swap'重命名功能或使用命名空間std'你有 – Tas
你的代碼看起來醜陋和太亂除去明顯的'。你的函數'swap'並不真正交換任何東西只會替換某個字符。重命名它。你在'std :: cin >> word [0];'後面做了什麼? –
這是另一個if/else語句。所以如果有人按1,它會改變第一個字母。 2改變了第二個。 –