注册 登录
编程论坛 C++教室

书上的范例,但VC6.0运行出错,新手请教

xueyicqq 发布于 2007-03-09 17:30, 629 次点击

//carrots.cpp -- food processing program
//uses and displays a variable

#include <iostream>

int main()
{
using namespace std; //declare an integer variable

int carrots;

carrots = 25;
cout<<"I have";
cout<<carrots;
cout<<"carrots.";
cout<<endl;
carrost = carrots - 1;
cout<<"Crunch, crunch. Now I have"<<carrots<<"carrots."<<endl;
return 0;
}

运行在VC++6.0,提示carrots是没申报的表示符,但我是一字不差的抄书上的,怎么会出错,我新手,有点纳闷,各位大虾帮忙,谢谢

5 回复
#2
半支烟2007-03-09 17:32
carrost = carrots - 1; //你好好看看这两个变量是一样的吗?
#3
xueyicqq2007-03-09 17:36

我太粗心了,谢谢2楼的大哥

#4
半支烟2007-03-09 17:42
别客气..下次注意点..
#5
heliujin2007-03-09 20:31
using namespace std  的位置可以随意放吗?
#6
半支烟2007-03-09 20:34

放在你要用的东西前面.....

1