我知道它可以获取 .txt 的一部分,然后将其转换为整数,然后将其存储在变量中,但是否可以在单个声明中实现。(变量需要是全局的)。
IE:
[data.txt]
1020
[convert_data.cpp]
#include<fstream>
fstream convert("data.txt");
//way to declare something equal to A PARTICULAR POINT in data.txt
int main()
{
//how would I take this block of code and simplify it to two DECLARATIONS (not
//function calls), or, if that's not possible or not practical, how would I make
//n and m (or var1 and var2) global AND CONSTANT?
char var1[5];
convert.getline(var1,2);
char var2[5];
convert.getline(var2,2);
const int n=atoi(var1);
const int m=atoi(var2);
return 0;
}