Hvis du kan bruge en vector i stedet for et array:
#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
#include <string>
int main()
{
// Open file
std::ifstream is("test.dat");
if(!is)
{
std::cout << "Failed to open file" << std::endl;
return 0;
}
// Storage for content
std::vector<std::string >MyVector;
// Read
std::copy(std::istream_iterator<std::string>(is),
std::istream_iterator<std::string>(),
std::back_inserter(MyVector));
// Write to std::cout
std::copy(MyVector.begin(), MyVector.end(), std::ostream_iterator<std::string>(std::cout, "\\n"));
}
PS: C og C++ er ikke script sprog, vi laver kode ikke scripts.
[Redigeret d. 01/02-05 20:12:03 af Bertel Brander]