能不能帮我看看,为什么我从msdn 帮助里面复制过来的程序运行出错

tanes 2003-10-20 03:03:34
编译显示 在查找预编译头指令时遇到意外的文件结尾 ,它显示的行号是我的最后一行 以外的一行, 这个程序一红 39行,它显示 40行出错. 我是初学者,很不明白了.

#include <iostream> // for i/o functions
#include <valarray> // for valarray
using namespace std;

#define ARRAY_SIZE 10 // array size
typedef valarray<int> INTVALARRAY; // type for valarray of ints

int main()
{
int i;
// Initialize val_array to 0, -1, -2, etc.
INTVALARRAY val_array(ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++)
val_array[i] = -i;

// Display the size of val_array.
cout << "Size of val_array = " << val_array.size() << "\n\n";

// Display the values of val_array before calling abs().
cout << "The result of val_array after calling abs():\n";
for (i = 0; i < ARRAY_SIZE; i++)
{
cout << val_array[i];
if (i < ARRAY_SIZE - 1)
cout << ", ";
}
cout << endl << endl;

// Display the result of val_array after calling abs().
INTVALARRAY abs_array = abs(val_array);
cout << "The result of val_array after calling abs():\n";
for (i = 0; i < ARRAY_SIZE; i++)
{
cout << abs_array[i];
if (i < ARRAY_SIZE - 1)
cout << ", ";
}
cout << endl;
}
...全文
78 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanglingyes 2003-10-23
  • 打赏
  • 举报
回复
NET的C++传统悠久,到目前语法变化不大,NET2003的c++与vc6.0编译器
差不多,VC模板中按简单到复杂分为抑制台->win32->mfc,其实这种包含
iostream.h文件的项目一般是说明某种功能语法的,重点在语言描述的过程中,
理解它的意思就得了。细入程序设计中还有。数据结构算法,把类分成抽象数据类型,
与数据结构。一个程序员的标准就是程序设计模式,能够学习,重用,组合软件组件的
各种技术,如果什么无关紧要的问题都要专,那年才能转化为实用的能力呀!
tanes 2003-10-21
  • 打赏
  • 举报
回复
我的意思是说为什么同样是 vc.net ,他参考书 上面就能够使用 #include <iostream.h>
我就不能用呢? 你们一般调试这种控制台的环境是什么啊? 怎么进的这个环境 , 我用的是vs2003 ,对环境有影响吗? 有一些个选项好象和 .net 也不太一样
wanglingyes 2003-10-21
  • 打赏
  • 举报
回复
这是很简章的,建立WIN32穿插项目,注意选择控制台选项,然后建立io.cpp空白文件,把你上一个复制进去,运行,当然,这个程序不完美,你的下一个程序是不是打错了某个标点?
tanes 2003-10-20
  • 打赏
  • 举报
回复
大哥能不能具体一点,说清楚一点好吗? 谢谢了
sonic6 2003-10-20
  • 打赏
  • 举报
回复
可以加入#include "stdafx.h"
拷贝一份stdfx.h就可以
另外还可以将文件的编译设置改为不需要自动预编译即可
tanes 2003-10-20
  • 打赏
  • 举报
回复
我从参考书上抄了一个程序,也出错,我从资料里面说vc.net是不能用 <iostream.h>的啊,但是参考书上 ,所有的都是这么写的, 还都给出结果了.




#include "stdafx.h"

#include <conio.h>
#include <iostream.h>

int _tmain (int argc,_TCHAR* argv[])
{
int i=1;
extern iostream cout <<"i:"<<i<<endl;


int &r_i=i;
r_i=2;
extern iostream cout<<"i"<<i<<endl;


int *p_r_i=&r_i;
extern iostream cout<<"p_r_i:"<<*p_r_i<<endl;

return 0;
}

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧