读书人

大哥大姐姐们!问个很菜的有关问题.谢

发布时间: 2012-03-20 14:01:11 作者: rapoo

大哥大姐姐们!问个很菜的问题....谢啦~!
小弟刚学C++刚两天,各位帮帮忙...谢谢
《C++ Primer Plus》 中文版 31页

// ourfunc.cpp -- defining your own function
#include <iostream>
void simon(int); //function prototyp for simon()

int main()
{
using namespace std;
simon(3);
cout < < "Pick an integer: ";
int count;
cin > > count;
simon(count);
cout < < "Done! " < < endl;
return0;
}

void simon(int n)
{
using namespace std;
cout < < "Simon says touch your toes " < < n < < "times. " < < endl;
}


书上说,运行后:
Simon says touch your toes 3 times.
Pick an integer:512
Simon says touch your toes 512 times.
Done!

512是用户输入的就是count的植

问:(我知道先调用simon()函数,第一次调用参数是3,第二次调用参数是变量count)

先出来 Simon says touch your toes 3 times.

cout < < "Simon says touch your toes 在哪用simon()被第一次调用的参数了

小弟刚学C++两天,各位帮帮忙...谢谢


[解决办法]
cout < < "Simon says touch your toes " < < n < < "times. " < < endl;

注意到这个 < < n 么?
就是void simon(int n) 传递进来的 参数 n

读书人网 >C++

热点推荐