#include <iostream>
#include <cstdlib>
#include <string>
#include <time.h>
using namespace std;
struct phoneBook
{
string name;
string address;
string phoneNumber;
};
void insertName(phoneBook print[])
{
print[256];
for (int i = 0; i < 1; i++)
{
cin >> print[i].name;
cin >> print[i].address;
cin >> print[i].phoneNumber;
}
}
void printBook(phoneBook print[])
{
print[256];
for (int i = 0; i < 256; i++)
{
cout << print[i];
}
}
int main()
{
srand(time(NULL));
cout << "xd";
}
在上面顯示的代碼中,我得到一個錯誤。錯誤是binary "<<": no operator found which takes a right-hand with
。仍然得到二進制「<<」:沒有發現運營商發現右邊<string>
我已經包含了字符串,因爲您可以看到,但它僅解決了>>
運算符的問題。如果你看代碼,在void printBook()
我有一個cout
命令cout << print[i];
。這就是發生錯誤的地方,而不是在int main(){cout << "xd";}
函數中。爲什麼錯誤不會影響int main中的<<
,但僅在void phoneBook()
?如果任何人有一個很好的解決方案,我會很樂意聽到它。提前致謝。
(你看到的代碼還沒有完成,我是比較新的C++(對不起,如果它看起來像一個可憎的,如果有代碼中的任何其他錯誤)。)
你認爲'print [256];'是做什麼的?你認爲'print [i]'是什麼? – user2357112
這是無關緊要的,但相關的:通常,不要在現代C++中使用C風格的數組('int foo [42]; phoneBook bar [100];')。 (但許多舊的教科書和指南仍然會教這個。)使用'std :: vector'代替 - 例如'std :: vector phoneBooks;'。 –