Вот что вы, возможно, могли бы сделать успешно:
std::string line;
std::string single_line;
fstream x("essai.txt");
first_iteration = true;
// Read all the data from the file and accumulate the results into a single line
while (std::getline(x,line)) {
if(first_iteration) {
first_iteration = false;
}
else {
single_line += ' ';
}
single_line += line;
}
// Position the file write pointer back to the beginning ...
// (that's most probably not needed at all, since the writing position was
// never changed in the previous code)
x.seekp(std::ios_base:beg);
// ... and write out the formerly accumulated input.
x << single_line;
Краткий пример:
require 'ostruct'
person = OpenStruct.new
person.name = "John Smith"
person.age = 70
person.pension = 300
puts person.name # -> "John Smith"
puts person.age # -> 70
puts person.address # -> nil
На основе того, что Вы говорите о хешах и. нотация я собираюсь принять Вас, означает другой вид кортежа, чем (1. "a")
вид. Вы, вероятно, ищете Struct
класс. например:
Person = Struct.new(:name, :age)
me = Person.new
me.name = "Guy"
me.age = 30