B
B
beduin012016-01-30 17:50:18
C++ / C#
beduin01, 2016-01-30 17:50:18

How to reach element in foreach?

The situation is this. I am getting values ​​from the database.

auto newimages = db.stmt.executeQuery("тут сам запрос");

  while(newimages.next())
  {
    string url = newimages.getString(4);
    string name = newimages.getString(6);

    string myalis = newimages.getString(10);
    
    string month = newimages.getString(11);
    string year = newimages.getString(12);

    urls ~= url; 
    names ~= name;
    myalises ~= myalis;
  }

Next, I iterate over the list of received URLs and do the operations I need with them:
foreach(i, url; urls)
  {

The question is what to do if I also need a list of `myalises` in this cycle. Let's say I want to match each `url` with `myalis`. How can I do all this inside foreach?
I am writing in Di, but since there are not many experts on it here, I am ready to find out how it could be done in other languages.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-01-30
@AtomKrieg

If the order in the urls list matches the order in the myaliases list.

std::list<string>::iterator myalis=myalises.begin();
for(const auto& url: urls) {
    std::cout << url << *myalis << std::endl;
    ++myalis;
}

A
Alexander Ruchkin, 2016-01-30
@VoidEx

dlang.org/phobos/std_range.html#zip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question