C++ C+;中全局数组初始化时出现语法和缺少类型说明符错误+;
对于以下代码行:C++ C+;中全局数组初始化时出现语法和缺少类型说明符错误+;,c++,arrays,global,C++,Arrays,Global,对于以下代码行: #include<iostream> #include<fstream> #include<string> void telephonebill(); void add(); void edit(); void readFile(); void display(); string names[100]; string addresses[100]; int tn[100]; int numCalls[100]; int tru
#include<iostream>
#include<fstream>
#include<string>
void telephonebill();
void add();
void edit();
void readFile();
void display();
string names[100];
string addresses[100];
int tn[100];
int numCalls[100];
int trunkCalls[100];
int numMobCalls[100];
int isdnNum[100];
int dueD[100];
int paymentD[100];
int numC = 0;
这些数组的声明有什么问题?您缺少名称空间: 您可以在include之后的文件开头添加以下内容(请注意,在更复杂的场景中,这可能是一个问题。)
或者,您可以在每次使用字符串时指定名称空间:
std::string
哪一行是第12行?第12行之前是什么?您是否包括
?您正在使用命名空间std执行
(许多人反对)或使用std::string代码>?你大概忘了一个
在声明名称之前
。第12行是字符串名称[100];在它之前是void display();您可能需要一个C++容器,而不是一组100长度数组,其中包含一个包含这些数据的简单结构。这里的内容非常混乱。您没有使用此源文件中的标准命名空间。因此,字符串
未知<代码>标准::字符串
将起作用(建议使用),或者(抖动)使用名称空间标准放置代码>在include之后。许多人建议不要使用名称空间
,而是建议按字面意思指定它:std::string
。它们被组织到一个名称空间是有原因的。两种解决方案都使用这个小示例。但在更复杂的情况下,使用名称空间会产生问题,这是事实。@tadman在头文件中比在端点源文件中要重要得多。然而,值得注意的是。
1>Project.cpp(12): error C2146: syntax error : missing ';' before identifier 'names'
1>Project.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Project.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Project.cpp(13): error C2146: syntax error : missing ';' before identifier 'addresses'
1>Project.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Project.cpp(13): error C2086: 'int string' : redefinition
1>Project.cpp(12) : see declaration of 'string'
1>Project.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
using namespace std;