I wanna make a program, but could not make,Plz provide me its code in c++.
The program is:
Write a program that read a text file, one line at a time, and prints the line as it was read and then prints the line with its text reversed. Print a blank line after each reversed line.
ofstream file("c:\\array.txt",ios::app);
ifstream file1("c:\\array.txt");
for(int i=0;i<5;i++)
{
cout<<"Enter value in text";
cin>>arr[i];
file<<arr[i]<<endl;
}
//ofstream file("c:\\array.txt",ios::app);
//ifstream file1("c:\\array.txt");
//file<<<<'\n';
//cout<<"The string is as follows:"<<endl;
//cout<<str;
for(i=0;i<5;i++)
{
file << "The is line "<<i;
}
file.close();
//cout<<"The list of string is as follows:"<<endl;
//while(!file1.eof())
//{
//while(getline(file1,line));
//cout<<"["<<line<<"]"<<endl;
file1.close();
getch();
}
I have compile the following program, but not working .There are 14 errors in it. Plz Correct it.
Even i have used namespace std,but not working, plz correct.
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
using namespace std;
void main()
{
clrscr();
char arr[100];
std::ofstream file("c:\\std.txt",ios::app);
std::ifstream file1("c:\\std.txt");
std::string line;
for(int i=0;i<5;i++)
{
cout<<"Enter value in text file";
cin>>arr[i];
file<<arr[i]<<endl;
file.close();
}
// Don't use the .h form headers in c++
//#include<iostream.h>
//#include<fstream.h>
//#include<stdio.h>
//#include<string.h>
// Use these instead
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
usingnamespace std;
//void main() // ERROR!
int main() // main function MUST be int
{
//clrscr();
char arr[100];
std::ofstream file("c:\\std.txt", ios::app);
std::ifstream file1("c:\\std.txt");
std::string line;
for (int i = 0; i < 5; i++)
{
cout << "Enter value in text file";
cin >> arr[i];
file << arr[i] << endl;
file.close();
}
std::getline(file1, line);
file << line << std::endl;
file1.close();
//getch();
return 0; // should return a value from main!
}
As you said that i should not use .h but then compiler does not open files.
there are errors like:
Unable to open cstdio
unable to pen cstring
and so on
none of any file is opening.
plz tell its solution