伊莉討論區

標題: 問題已解決--C++編譯錯誤,還煩請惠予協助,謝謝 [打印本頁]

作者: wlsho    時間: 2018-4-28 10:11 PM     標題: 問題已解決--C++編譯錯誤,還煩請惠予協助,謝謝

本帖最後由 wlsho 於 2018-4-28 10:40 PM 編輯

我剛才把副檔名改成c++
然後再加入一行
using namespace std;

問題就解決了.....
抱歉浪費大家的時間
謝謝大家進來看


抱歉,我今天試著用DEV 跑C++可是被很基礎的東西卡了7個小時
沒有任何一點進展
想的到的方法都試過
也不知道該怎麼找答案出來了
實在沒辦法
還請大家幫忙

問一個很白癡的問題

我按照書本打了一組程式如下:
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int stonetolb(int);
int main() {
        int stone;
        cout<<"Enter the weight in stone: ";
        cin >> stone;
        int pound =stonetolb(stone);
        cout <<stone<<" stone are ";
        cout<<pound<<" pounds.\n";
        return 0;
}

int stonetolb(int sts)
{
        return 14*sts;
}


可是編譯器跑出一堆的錯誤,錯誤截圖為:
[attach]123189127[/attach]

10個錯誤的訊息都類似下面這個........
[Error] 'cout' was not declared in this scope
[Note] suggested alternative:
in file included form 2018042888.cpp
[Note] 'std::cout'
[Error] 'cin' was not declared in this scope



請問我是哪邊打錯嗎?
還是跟本是我在DEV上面的設定錯誤?


如果我發錯地方,或是我真的太笨到不會找答案,還煩請不吝告知.....謝謝
只是我在這個問題上面,已經卡了7個小時也毫無進展
快瘋了.............




作者: tryit244178    時間: 2018-4-30 01:56 PM

本帖最後由 tryit244178 於 2018-5-5 09:10 AM 編輯

補充一下,C的副檔名是c,C++的副檔名是cpp。沒這個"using namespace std"才是問題
作者: z1090128    時間: 2018-5-1 10:29 PM

"using namespace std"在C++是蠻重要的,不過我平常都用VS寫,所以很少碰到這個
作者: 神之風想    時間: 2018-5-5 09:29 AM

謝謝大大的分享喔,小弟覺得很好喔~解決了我的問題
作者: jackyo04    時間: 2018-6-21 05:54 PM

找書練習時,請先確認你使用的版本是不是跟書本使用的一樣,不一樣就會發生這種問題!!




歡迎光臨 伊莉討論區 (http://www85.eyny.com/) Powered by Discuz!