类型声明错误

Error with type declaration

本文关键字:错误 声明 类型      更新时间:2023-10-16

我一直得到错误"此声明没有存储类或类型说明符。"我已经检查了分号,并包含了相关的库。

#include <iostream>
#include <fstream>
using namespace std;
const int n = 8;
double p[n] = {1.23, .97, .86, .77, .69, .65, .71, .50};
double pi[n] = {.74, .70, .66, .68, .65, .62, .60, .54};
double z[n] = {.25, .35, .45, .55, .65, .75, .85, .95};
ofstream myfile;
myfile.open("ppilow.txt"); //Error here

尝试用以下代码替换myfile.open("ppilow.txt");:

int main(int argc, char *argv[])
{
  myfile.open("ppilow.txt");
  return 0;
}

说明:你不能把指令放在函数体之外。

但是最好避免声明全局变量,所以我建议你也把它移到body中