String Array output to a txt file problem.

Hello I want to write an Array in a TXT File, but it donĀ“t work.
My program just write a hexcode into the txt file.
So how I can solve this problem. Here is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>

using namespace std;

int main()
{
string inventory[5] = {"The ", "distortion ", "is ", "totally ", "solid"};

ofstream myfile;
  myfile.open ("example.txt");
  myfile << inventory ;
  myfile.close();


system("pause");
getchar();
return 0;
}
  
You declare an array of strings, which decays to a pointer to the first string when you use it non-indexed. Either declare a single string or loop through every word and output it separately.
Topic archived. No new replies allowed.