首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++变量值自己变了.该如何解决

2012-09-14 
C++变量值自己变了..#include iostream#include fstreamusing namespace stdconst int MAXN 5bool

C++变量值自己变了..
#include <iostream>
#include <fstream>
using namespace std;

const int MAXN = 5;
bool G[MAXN][MAXN];
int n, m;// n: 顶点, m: 线条

void main()
{
ifstream ifile("topo.txt");
ifile >> n >> m;
m = 5;
for (int i = 0; i != m; ++i) {
int u, v;
ifile >> u >> v;
G[u][v] = true;
}
ifile.close();
}

topo.txt内容是:
5 5
1 5
4 2
4 5
2 3
5 3

for (int i = 0; i != m; ++i)会无限循环, 最后一次循环的时候m == 1, 明明是5的;;

[解决办法]

探讨
#include <iostream>
#include <fstream>
using namespace std;

const int MAXN = 5;
bool G[MAXN][MAXN];
int n, m;// n: 顶点, m: 线条

void main()
{
ifstream ifile("topo.txt");
ifile >> n >> m;
……

热点排行