For循环未执行
For loop not getting executed
我有以下代码片段,在其中我试图将一些语句打印到XML文件中:
void parseXML::writeStruct(std::fstream& abc,std::string prnt)
{
for (map<string,struct structSet>::iterator it = structData.begin();it != structData.end();it++)
{
if (((it->second.parent.compare("")==0) && (it->second.written == false)))
{
bool write = true;
if (it->second.type.compare("")==0)
{
for (set<std::string>::iterator i = it->second.fields.begin(); i != it->second.fields.end(); i++)
{
map<string,struct fieldSet>::iterator fd = fieldData.find(*i);
if (fd != fieldData.end())
{
std::string type = fd->second.type;
map<string,struct structSet>::iterator ntC = structData.find(type);
if (ntC != structData.end())
{
if (ntC->second.type.compare("") != 0)
{
map<string,struct structSet>::iterator ntC = structData.find(ntC->second.type);
if (ntC == structData.end()|| ntC->second.type.compare("")!= 0||ntC->second.written == false)
{
continue;
}
}
else
{
map<string,struct structSet>::iterator ntC = structData.find(ntC->second.type);
if (ntC->second.parent.compare(it->second.name))
{
}
else if (ntC->second.written == true)
{
abc << INDENT << "t" <<"t" << "<nonterminal ref= "" << ntC->second.name.c_str() << "">" << std::endl;
abc << INDENT << "t" << "t" <<"t" << "<name>" << fd->second.name.c_str() << "</name>" << std::endl;
abc << INDENT << "t"<< "t" << "</nonterminal >" << std::endl;
}
}
}
问题是它没有执行第一个for
循环:
for (map<string,struct structSet>::iterator it = structData.begin(); it != structData.end(); it++)
可能的原因是什么?
这里有一个(希望)完整的列表,很抱歉有明显的条目,但我们不知道你有多有经验:
structData
为空structData
已损坏,导致应用程序崩溃parseXML::writeStruct
从未执行- 执行了for循环,但以下(
if
,for
)条件失败,您对此解释错误
选择调试器或添加跟踪消息(不要忘记使用endl
,因为输出通常是行缓冲的,在崩溃时会丢失)。
注意:只发布代码的相关部分,其余部分对我们来说只是噪音(除非你想要一个代码审查https://codereview.stackexchange.com/)
相关文章:
- 在映射擦除c++期间执行循环的次数
- C++-For循环未执行
- 未在函数C++中执行的循环
- 为什么切换 for 循环的顺序会显著改变执行时间?
- 将执行循环拆分为多个线程 (1-N-1-N-1..)
- 在类 c++ 中执行 while 循环
- C++ - 使用用户输入的字符串数据检查结构字符串数据(无限执行 while 循环)
- 如何仅在父循环的所有迭代都为真时才执行嵌套的 if 语句?
- 在"0"输入停止循环之前正确执行 while 循环?
- 为什么其中一个 while 循环没有被执行 (C++)?
- 为什么 std::chrono 在测量循环和编译器优化的并行 OpenMP 的执行时间时不起作用?
- 需要帮助转换以执行循环
- 在CIN为真后,使用一段时间循环,然后执行循环
- 为什么要执行循环五次并停止
- 如何为回调执行循环 (C++)
- 执行循环,直到系统时间到达特定日期/时间
- 如何在执行循环(C++)时使间隔为秒
- C++菜单的“执行”循环.测试大写和小写:
- ICC 未执行循环不变代码移动
- 程序不执行循环