| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 356 人关注过本帖
标题:C++ 编程,找了好久不知哪里出错了,望大神指教
只看楼主 加入收藏
helloworldll
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-1
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
C++ 编程,找了好久不知哪里出错了,望大神指教
我想要打开一个文件,文件里的数据格式如下
5
 Franks,Tom 2 3 8 3 6 3 5
 Gates,Bill 8 8 3 0 8 2 0
 Jordan,Michael 9 10 4 7 0 0 0
 Bush,George  5 6 5 6 5 6 5
 Heinke,Lonnie  7 3 8 7 2 5 7
这是我的程序

#include <iostream>
 #include <fstream>
 # include <cstring>
 # include <string>
 using namespace std;
 int main()
 {
     ifstream fin;
     fin.open("empdata.txt");
     int themax;
     string name[50];
     int time[50][50];
     fin >> themax;
     int sumtime[themax];
     for(int i = 0; i < themax; i++)
     {
         sumtime[i] = 0;
     }
     for(int i=0;i<themax;i++)
     {
     fin>>name[i];
     for(int j=0;j<7;j++)
     {
     fin>>time[i][j];
     sumtime[i]=sumtime[i]+time[i][j];
     }
     }
     for (int a = 0;a<themax-1;a++)
     {
         for (int b=0;b<themax-a;b++)
         {
         int minnum=sumtime[b];
         if (sumtime[b]<sumtime[b+1])
         {
             minnum=sumtime[b];
             sumtime[b]=sumtime[b+1];
             sumtime[b+1]=sumtime[b];
             swap(name[b],name[b+1]);
         for (int b=0;b<themax;b++)
         {
             for (int k=0;k<7;k++)
             {
                 swap(time[b][k],time[b+1][k]);
             }

     }
         }
         }
     }
      cout << name<< "   ";
      cout << time<< "   ";
      cout << sumtime;
      cout << endl;
     fin.close();

     return 0;
     }
为什么运行结果是
0x28fd50   0x28d640   0x28d570

 Process returned 0 (0x0)   execution time : 0.220 s
 Press any key to continue.
我的程序是打开一个文件,将文件里的数据存储在数组当中,然后计算出总和以后用冒泡排序法排序,每个人的名字和工作时间也要随之移动,我的程序对吗?为什么会出这种情况?还有我的swap函数用的对吗?望指教。
2014-12-02 23:57
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:20 
目测你的NAME TIME SUMTIME都是数组呢  所以输出的是地址  也没啥奇怪的啊

DO IT YOURSELF !
2014-12-03 09:34
快速回复:C++ 编程,找了好久不知哪里出错了,望大神指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015392 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved