Автор: oleg_alexeev (26.02.2007 в 10:49)
Вот аналог приведенного PHP-кода:
#include <fstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<string> StringArray;
int main(int argc, char *argv[])
{
string str;
ifstream in;
in.open("c:/tmp/test.txt");
if (in.fail()) return 0;
StringArray content;
while (!in.eof())
{
in >> str;
content.push_back(str);
}
in.close();
ofstream out;
out.open("c:/tmp/test.txt");
if (out.fail()) return 0;
str = "Hello world!";
out << str << endl;
return 0;
}
|
Содержимое файла сохранено в массиве 'content'.
В файл выведена строка "Hello world!"