// Creates a file and prints the string you type into it.
#include <iostream>
#include <fstream>
#include <cstring> // ... For 'strcmp' ect
#include <cstdlib> // ... For system("PAUSE")
using namespace std;
int main()
{
ofstream outfile;
char word[200]; // Char array name 'word'
outfile.open("file.txt", ios::out);
do
{
cout << "Type a word. ";
cin.getline(word,200);
outfile << word <<endl;
}
I need some help with stringing...it seems that "string" itself isn't a keyword and i tried including string
Maybe others; but here is just one way...
// Creates a file and prints the string you type into it.
#include <iostream>
#include <fstream>
#include <cstring> // ... For 'strcmp' ect
#include <cstdlib> // ... For system("PAUSE")
using namespace std;
int main()
{
ofstream outfile;
char word[200]; // Char array name 'word'
outfile.open("file.txt", ios::out);
do
{
cout << "Type a word. ";
cin.getline(word,200);
outfile << word <<endl;
}
while(strcmp(word, "" ) != 0); // strcmp compares two strings: Uses <cstring>
outfile.close();
system("PAUSE");
return 0;
}
j@ck_
Another way ?...
Smaller and simple.
// Creates a file and prints the string you type into it.
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
ofstream outfile;
string myBff; // Enter single line with no spaces...
outfile.open("file.txt", ios::out);
cout << "Type a word: ";
cin >> myBff;
outfile << myBff <<endl;
outfile.close();
system("PAUSE");
return 0;
}
j@ck_
Thanks a bunch
#include<string>
string xxx;
cin>>xxx;
// using strings in your program