I just need a simple program fragment that saves sentences/phrases and can load as exactly as the input. Do not rely on this code as I had made several failed attempted solutions. This is only what I remember:
#include<fstream.h>
#include<iostream.h>
#include<string.h>
#include<conio.h>
main()
{int x=0;char strings[5][50];
ofstream save("data.txt",ios::out)
while(x<5)
{gets(strings[x]);
save<<strings[x]<<endl;
x++;}
save.close();
x=0;
/* ifstream load("data.txt",ios::in);
while(!load.eof())
{load>>strings[x];
puts(strings[x]);
x++;
}
load.close(); */
getche();
return 0;
}
I just want these strings to retain the space between words. my problem is that these spaces are vanishing and strings tend to contract instead or just gave the first word.
Input:
the food is good
going high
delicious pie
Expected output:
the food is good
going high
delicious pie
Not this (my problem):
the
going
delicious
--OR--
thefoodisgood
goinghigh
deliciouspie
I will need it to store sentences in a simple manner so I'm focused on saving sentences and loading it exactly as what the input gives. Don't give tips because my mind burnt out on studying functions, just give the code directly as I only need a very simple program. Thank you.