我剛開始讀加速C++,我試圖通過練習來上班的時候,我碰到這一個:編寫程序打印「Hello,world!」程序
0-4. Write a program that, when run, writes the Hello, world! program as its output.
於是我想出了這個代碼:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << helloWorld << endl;
cin.get();
return 0;
}
void helloWorld(void)
{
cout << "Hello, world!" << endl;
}
我不斷收到錯誤'helloWorld' : undeclared identifier
。我認爲我應該做的是爲helloWorld做一個函數,然後調用該函數的輸出,但顯然這不是我所需要的。我也試過把helloWorld()
放在主要位置,但那也沒有幫助。任何幫助是極大的讚賞。
'helloWorld()'需要_declared_纔可以使用。 –
我不清楚作業的內容。他們希望你編寫一個打印「你好,世界!」的程序或者打印「代碼」爲「Hello,World!」的程序風格的程序?這兩者有微妙的不同。 –
@NikBougalis:從引用的文本開始,它應該顯然是後者。 – Grizzly