I am simply trying to write data from multimap to a text file in C++. My multimap contains two values at one key, although it outputs both values on the console, but it writes the key and value of the first one only in the file (means it writes only "a" and "100"). Why isn't it writing both values to File? This is my code
int main() {
multimap<string, string> rec;
rec.insert({"a", "100"});
rec.insert({"a", "200"});
writeFile("a", rec);
}
void writeFile(string a, multimap<string, string> rec) {
ofstream data;
for (auto i = rec.find("a"); i != rec.end(); i++) {
data.open("file4.txt");
data << i->first << '\t' << i->second << '\n';
}
}