C語言程序設計原理和實踐書中例子
你好我是一個C語言的新手,經人介紹在看C程序設計原理和實踐這本書按照書中例子#include“std_lib_facilities.h”
int main(){ cout<<"please enter your first name(followed by 'enter'):\n"; string first_name; cin>>first_name; cout<<"hellr"<<first_name<<"!\n";}std_lib_facilities.h這個文件已經下載並放入了\Include可在編譯的時候出現如下錯誤VC.CPPd:\c語言編寫練習\vc.cpp(1) : error C2018: unknown character '0xa1'd:\c語言編寫練習\vc.cpp(1) : error C2018: unknown character '0xb0'd:\c語言編寫練習\vc.cpp(1) : error C2006: #include expected a filename, found 'identifier'd:\c語言編寫練習\vc.cpp(5) : error C2065: 'cout' : undeclared identifierd:\c語言編寫練習\vc.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [52]'d:\c語言編寫練習\vc.cpp(6) : error C2065: 'string' : undeclared identifierd:\c語言編寫練習\vc.cpp(6) : error C2146: syntax error : missing ';' before identifier 'first_name'd:\c語言編寫練習\vc.cpp(6) : error C2065: 'first_name' : undeclared identifierd:\c語言編寫練習\vc.cpp(7) : error C2065: 'cin' : undeclared identifierd:\c語言編寫練習\vc.cpp(7) : warning C4552: '>>' : operator has no effect; expected operator with side-effectd:\c語言編寫練習\vc.cpp(8) : error C2297: '<<' : illegal, right operand has type 'char [6]'d:\c語言編寫練習\vc.cpp(9) : warning C4508: 'main' : function should return a value; 'void' return type assumed執行 cl.exe 時出錯.
VC.OBJ - 1 error(s), 0 warning(s)
。如果您有空的話,非常感謝。
最佳回答:
你的錯誤類型是:
vc.cpp(1) : error C2018: unknown character '0xa1'd
error C2006: #include expected a filename, found 'identifier'd:\c
vc.cpp(5) : error C2065: 'cout' : undeclared identifierd:\c
\vc.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [52]'d
: error C2297: '<<' : illegal, right operand has type 'char
error C2146: syntax error : missing ';' before identifier 'first_name'd
分別把他們復制到百度裡收索一下,然後看看翻譯和別人的問題,然後把自己的程序分析一下,會不會有同樣的問題,有的話就解決了…,我平時出錯都是這麼解決的。