|
|
发表于 16-10-2008 10:06 AM
|
显示全部楼层
回复 18# Wongkokchoy 的帖子
自学的话, 别用 turbo c++ 了, 太旧了。
现在不在 hometown, 无法试用turbo c++, 因此不得而知是否turbo c++ 的问题, 不过gcc, mingw 这里一切正常 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:10 AM
|
显示全部楼层
原帖由 onlylonly 于 16-10-2008 10:03 AM 发表 
很明显是文件名字错误, 应该你是将 data.dat.txt 当成 data.dat
在windows里, 默认是没有显示文件 extention 的, 去 windows explorer 或 my computer / tools/ folder options/ view/ advance steeings 哪里, ...
跟着你说的去做了,可是还是一样
如果是自学的话我都不会去用borland C++ 咯,可是是大学的课程]需要我才会用的。。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:11 AM
|
显示全部楼层
回复 18# Wongkokchoy 的帖子
试一试这个能不能跑- #include <iostream>
- using namespace std;
- int funct();
- int main()
- {
- int swap;
- cout << "test 1 = " << funct() << endl;
- swap = funct();
- cout << "test 2 = " << funct() << endl;
- return 0;
- }
- int funct()
- {
- return 100;
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:12 AM
|
显示全部楼层
回复 22# Wongkokchoy 的帖子
|
过后你要去看看你的 name.dat 的名字是什么。 是否与你的program放在同一个folder里面 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:13 AM
|
显示全部楼层
回复 23# onlylonly 的帖子
run那边一片空白 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:14 AM
|
显示全部楼层
回复 24# onlylonly 的帖子
我的dat file 放在 desktop 罢了,原来要放在folder里面阿, lecturer 提也没提到 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:17 AM
|
显示全部楼层
回复 25# Wongkokchoy 的帖子
这个?- #include <iostream.h>
- int funct();
- int main()
- {
- int swap;
- cout << "test 1 = " << funct() << endl;
- swap = funct();
- cout << "test 2 = " << funct() << endl;
- return (0);
- }
- int funct()
- {
- return (100);
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:19 AM
|
显示全部楼层
回复 26# Wongkokchoy 的帖子
|
编程无法靠lecturer的, 很多编程的知识讲师无法传输的。要靠自己累计经验, 多想, build up algorithm。 然后讲师也会忘记讲很多的 syntax 。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:20 AM
|
显示全部楼层
刚刚我run的时候已经把namespace delete 掉了。
这个也是不行。。。。
dat file是不是要放在批program file〉borland C++ 那边?
[ 本帖最后由 Wongkokchoy 于 16-10-2008 10:22 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:22 AM
|
显示全部楼层
回复 29# Wongkokchoy 的帖子
这样的话我也不懂了。。。。
syntax logic 都没错, 不知道是什么问题了 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:25 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:28 AM
|
显示全部楼层
原帖由 onlylonly 于 16-10-2008 10:25 AM 发表 
放在你的source code file哪里
那是指那里 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:30 AM
|
显示全部楼层
回复 32# Wongkokchoy 的帖子
|
就是你的 .cpp file 哪里, 比如你的code 放在 c: , 那么 name.dat 就放在 c: |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:39 AM
|
显示全部楼层
|
现在可以open file 了,可是跟我所enter的资料不一样 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 10:45 AM
|
显示全部楼层
回复 34# Wongkokchoy 的帖子
|
如何不一样? 看看你的data.dat 文件里面的资料是什么。。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 11:28 AM
|
显示全部楼层
如果你的 open file syntax 里面没有指定data file 的路径,例如:
ifstream file_input ("name.dat");
那么,compiler 会默认你的档案必须和你 compile 出来的 .exe 档案在同一个地点。如果你的 .exe 档案是在 C:\MyFolder 里面,那你的 data file 也必须在那里。如果你有指定档案的地点例如:
ifstream file_input ("D:\\AnotherFolder\\name.dat");
那你的档案就必须在指定的文件夹里面。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 11:32 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 06:18 PM
|
显示全部楼层
就是说,我key in 在dat file 那边的只是名字罢了,可是多了很多乱码。

[ 本帖最后由 Wongkokchoy 于 16-10-2008 08:11 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2008 11:09 AM
|
显示全部楼层
我试过了,你原本的code并没错,是你的次序错了,应该把 file_input >> name; 移去前面:- void main()
- {
- char name[100];
- ifstream file_input ("name.dat");
- for (int x=1; !file_input.eof(); x++)
- {
- file_input >> name; //你得先读取了资料才能print出来啊,老兄!
- cout << "\n\t" << x << "\t " << name;
- }
- file_input.close();
- getch();//为了方便看output的,可以无视。
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-10-2008 12:41 PM
|
显示全部楼层
我更正了我的错误了,可是。。。
 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|