Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;外部字符串数组不可见 我在C++开发中是新手,因为我在网上学习了关于ExtUnt变量——我尝试过它的字符串变量,它的工作很好。但是我必须使用字符串变量,因为它不工作。请看下面的< < /P>_C++ - Fatal编程技术网

c++;外部字符串数组不可见 我在C++开发中是新手,因为我在网上学习了关于ExtUnt变量——我尝试过它的字符串变量,它的工作很好。但是我必须使用字符串变量,因为它不工作。请看下面的< < /P>

c++;外部字符串数组不可见 我在C++开发中是新手,因为我在网上学习了关于ExtUnt变量——我尝试过它的字符串变量,它的工作很好。但是我必须使用字符串变量,因为它不工作。请看下面的< < /P>,c++,C++,globals.h #include <iostream> using namespace std; #ifndef SIMULATIONFILEPARSER_GLOBALS_H #define SIMULATIONFILEPARSER_GLOBALS_H //sequence of files to be execute extern string ipFiles[]; #endif //SIMULATIONFILEPARSER_GLOBALS_H #pragma once

globals.h

#include <iostream>

using namespace std;

#ifndef SIMULATIONFILEPARSER_GLOBALS_H
#define SIMULATIONFILEPARSER_GLOBALS_H
//sequence of files to be execute
extern string ipFiles[];
#endif //SIMULATIONFILEPARSER_GLOBALS_H
#pragma once

#include <string>
#include <vector>

extern std::vector<std::string> ipFiles;
main.cpp

#include "../headers/globals.h"
//sequence of files to be execute
string ipFiles[] = {"in.relaxSubstrate", "in.relaxFluid"};
#include <iostream>
#include "Source/headers/globals.h"

int main() {
    for (string &ipFileName :ipFiles) {
        std::cout << ipFileName << std::endl;
    }
    return 0;
}
std::vector<std::string> ipFiles{"in.relaxSubstrate", "in.relaxFluid"};
#包括
#包括“Source/headers/globals.h”
int main(){
用于(字符串和ipFileName:ipFiles){

std::cout此循环不知道数组的大小

for (string &ipFileName :ipFiles)
全球气候变化

extern string ipFiles[2];
global.cpp中的更改

string ipFiles[2] = {"in.relaxSubstrate", "in.relaxFluid"};

在此之后,您的代码应该能够正确编译。

编译器不会抱怨不可见的符号。它告诉您,类型不完整:

类型为“std::uu cxx11::basic_string[]”的表达式的基于范围的“for”类型不完整

在编译器知道数组的大小之前,它无法编译基于范围的for循环。若要更改此设置,您需要声明一个完整的类型。这可能是一个具有显式大小的数组,或者-这是推荐的解决方案-一个标准容器1:

globals.h

#include <iostream>

using namespace std;

#ifndef SIMULATIONFILEPARSER_GLOBALS_H
#define SIMULATIONFILEPARSER_GLOBALS_H
//sequence of files to be execute
extern string ipFiles[];
#endif //SIMULATIONFILEPARSER_GLOBALS_H
#pragma once

#include <string>
#include <vector>

extern std::vector<std::string> ipFiles;


1编译时不需要知道标准容器的大小。编译器所需要的是(
begin()
end()的(正向)迭代器受控序列的
。另一方面,数组不提供这些函数作为成员函数,编译器需要生成它们。它需要知道生成等价于
end()的函数的大小

#在任何地方使用它。不要在头文件中使用
名称空间std;
。我正在使用字符串数组,我包括了它,但它仍然会出现相同的错误编译器没有抱怨,符号不可见。它告诉你,它不知道它的完整类型。它看到的只是一个大小未知的数组。它不能不可能在未知类型上构造基于范围的for循环。已删除“使用命名空间std;”,但仍然没有success@ErKandarpPatel请用IInspectable检查答案。这是一个更好的方法。我的答案只是解决了你的问题。但这不是好的做法。