mardi 3 mars 2015

Understand meaning of { when creating stream objects

I came across the following code



#include <iterator>
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>

int main() {

std::string inputfilename, outputfilename;

std::cin >> outputfilename;

std::ofstream outputfile{ outputfilename };

outputfile << "I exist Yo!";

return 0;
}


My first reaction was that it should not compile. I had never seen the outputfile{ outputfilename }; usage. Can someone please tell me what feature of the C++ language defines the behavior of {} in this instance?


P.S. The code works and does what you would expect.


Aucun commentaire:

Enregistrer un commentaire