ifstream "push_back"'en
-
hi,
ich möchte alles was im ifstream "read" drinnen ist, in einen Vektor speichern, einen Grund gibts daweil noch nicht

// is ne funktion .. // sonstiges std::ifstream read; read.open(file.c_str()); // .. read.push_back(field);field ist vom Typ std::vectorstd::string, file vom const std::string&.
Freue mich über Antworten

-
stell doch mal eine frage
-
antwort schrieb:
stell doch mal eine frage
aso, hab ich vergessen, sorry

ich möchte alles was im ifstream "read" drinnen ist, in einen Vektor speichern, einen Grund gibts daweil noch nicht
wie kann das realisieren?
-
Danie1 schrieb:
ich möchte alles was im ifstream "read" drinnen ist, in einen Vektor speichern, ...
Meinst Du es so:
std::ifstream read( file.c_str() ); std::vector< std::string > field( (std::istream_iterator< std::string >( read )), std::istream_iterator< std::string >() );Dann stehe alle Worte aus der Datei im vector field.
Du brauchst dazu die includes#include <fstream> #include <string> #include <iterator> // istream_iterator #include <vector>Gruß
Werner