为什么';t在C+上工作+;使用引用地址指针编译? 我是一个计算机科学的学生,我第一次上C++课。我在理解我的代码时遇到问题: // This program uses the address of each element in the array. #include <iostream> using namespace std; int main() { const int NUM_COINS = 5; int coins[NUM_COINS] = {5, 1, 25, 5, 10}; int *p1; // Pointer to a double. int count; // Counter variable. // Use the pointer to display the values in the array. cout << "Here are the values in the coins array: \n"; for(count = 0; count << NUM_COINS; count++) { // Get the address of an array element p1 = &coins[count]; // Display the contents of the element cout << *p1; } cout << endl; return 0; } //此程序使用数组中每个元素的地址。 #包括 使用名称空间std; int main() { const int NUM_硬币=5; int硬币[NUM_硬币]={5,1,25,5,10}; int*p1;//指向双精度的指针。 int count;//计数器变量。 //使用指针显示数组中的值。 cout

为什么';t在C+上工作+;使用引用地址指针编译? 我是一个计算机科学的学生,我第一次上C++课。我在理解我的代码时遇到问题: // This program uses the address of each element in the array. #include <iostream> using namespace std; int main() { const int NUM_COINS = 5; int coins[NUM_COINS] = {5, 1, 25, 5, 10}; int *p1; // Pointer to a double. int count; // Counter variable. // Use the pointer to display the values in the array. cout << "Here are the values in the coins array: \n"; for(count = 0; count << NUM_COINS; count++) { // Get the address of an array element p1 = &coins[count]; // Display the contents of the element cout << *p1; } cout << endl; return 0; } //此程序使用数组中每个元素的地址。 #包括 使用名称空间std; int main() { const int NUM_硬币=5; int硬币[NUM_硬币]={5,1,25,5,10}; int*p1;//指向双精度的指针。 int count;//计数器变量。 //使用指针显示数组中的值。 cout,c++,macos,C++,Macos,Reason:您没有正确使用比较运算符。将其更改为“Reason后:您没有正确使用比较运算符。将其更改为“后,我没有看到任何问题,除了for循环中的一个问题: for(count = 0; count << NUM_COINS; count++) //^^ for(count=0;count除了您的for循环中的一个问题外,我看不到任何问题: for(count = 0; count << NUM_COINS; count++)

Reason:您没有正确使用比较运算符。将其更改为“Reason后:您没有正确使用比较运算符。将其更改为“后,我没有看到任何问题,除了
for
循环中的一个问题:

for(count = 0; count << NUM_COINS; count++)
                   //^^

for(count=0;count除了您的
for
循环中的一个问题外,我看不到任何问题:

for(count = 0; count << NUM_COINS; count++)
                   //^^


for(count=0;count对不起,格式不正确,我不理解此文件的格式site@J-e-L-Lo:使用
{}
在编辑器窗口上标记以格式化代码。代替比较运算符的左移位运算符是一个错误,但我仍然不明白为什么会出现std::iostream错误。一旦修复了它,其余的代码对我来说就正常了。@Sriram:Yup,我相信这个错误是特定于编译器的。有趣的是,g++command除了显示字符串内容外,程序运行正常。很抱歉,格式不正确,我不理解此文件的格式site@J-e-L-Lo:使用
{}
在编辑器窗口上标记以格式化代码。代替比较运算符的左移位运算符是一个错误,但我仍然不明白为什么会出现std::iostream错误。一旦修复了它,其余的代码对我来说就正常了。@Sriram:Yup,我相信这个错误是特定于编译器的。有趣的是,g++command运行程序很好,只是显示了字符串内容。@Nawaz:这肯定是个错误,但有趣的是,它是在我的机器上编译的。此外,这个错误是否会导致std::iostream错误?@Sriram:left shift在语法上是正确的。因此它会编译。另外,std::iostream错误来自其他地方,而不是您正在编写的代码我在这里引用了。?你说的不是代码是什么意思。我在我的macbook pro 2010上编译了相同的代码,它给了我这些错误。@J-e-L-L-o:你能编译并运行任何其他使用
iostream
的程序吗?这太愚蠢了,太奇怪了……我更改了左移位运算符,但它仍然没有编译。我将cpp文件保存到了另一个租一个目录,bam就可以了。Thanx伙计们。@Nawaz:这肯定是一个bug,但有趣的是,它是在我的机器上编译的。而且,这个bug是否会导致std::iostream错误?@Sriram:left shift在语法上是正确的。所以它会编译。另外,std::iostream错误来自其他地方,而不是你在这里引用的代码。你怎么办你的意思不是代码。我在macbook pro 2010上编译的是同一个代码,它给了我这些错误。@J-e-L-L-o:你能编译并运行任何其他使用
iostream
的程序吗?这太愚蠢了……我更改了左移位运算符,但它仍然没有编译。我将cpp文件保存到另一个目录,然后bam它工作,Thanx伙计们。