Iterating over a QMap with for

前端 未结 9 1845
执笔经年
执笔经年 2021-01-31 07:02

I\'ve a QMap object and I am trying to write its content to a file.

QMap extensions;
//.. 

for(auto e : extensions)
{
  fou         


        
9条回答
  •  感动是毒
    2021-01-31 07:56

    If you want the STL style with first and second, do this:

    for(auto e : extensions.toStdMap())
    {
      fout << e.first << "," << e.second << '\n';
    }
    

    If you want to use what Qt offers, do this:

    for(auto e : extensions.keys())
    {
      fout << e << "," << extensions.value(e) << '\n';
    }
    

提交回复
热议问题