Stream Functions |
Program |
Output |
COUT |
#include
using namespace std;
int main() {
cout<<"Wisdom Materials";
}
|
Wisdom Materials |
PUTS |
#include
using namespace std;
int main() {
puts("Wisdom Materials");
}
|
Wisdom Materials |
CIN |
#include
using namespace std;
int main()
{
string str;
cout<<"Enter a string:";
cin>>str;
cout<<"Number entered using cin is "<
}
|
Enter a string:
Wisdom
Output
Wisdom
|
GETS |
#include
using namespace std;
int main() {
char str[10];
puts("Enter a String:");
gets(str);
puts("Entered a String: ");
puts(str);
}
|
Enter a String:
Wisdom
Entered a String:
Wisdom
|
Read and write data to a file |
#include
#include
int main() {
char data[200];
fstream file;
file.open ("data.txt", ios::out | ios::in );
cout << "Enter data to write to a file" << endl;
cin.getline(data, sizeof(data));
//Writing to file
file << data << endl;
//Reding from file
file >> data;
cout << data << endl;
file.close();
return 0;
}
|
Enter data to write to a file
Wisdom
Output
Wisdom
|