Reputation: 51
hello i have a c++ code for convert latin alphabet to arabic alphabet It works well for all characters except space character When space character needs to be printed in the file, no character is printed in the file how i can fix it ?
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
// ofstream constructor opens file
ofstream outClientFile( "f2.txt", ios::out );
// exit program if unable to create file
if( !outClientFile )// overloaded ! operator
{
cerr << "File could not be opened" << endl;
exit( 1 );
} // end if
cout << "Enter Your Text:" << endl;
outClientFile<<"your text is :"<<endl;
char ch;
cin >> ch;
if (ch == 'a') outClientFile << "ش";
else if (ch == 'b') outClientFile << "ذ";
else if (ch == ' ') outClientFile << " ";
else if (ch == '.') outClientFile << " ";
else outClientFile << ch;
} // end main
Upvotes: 0
Views: 81
Reputation: 1374
Instead of:
cin >> ch;
you should use:
ch = getchar();
This way you'll be able to read spaces too.
Don't forget to include:
#include <cstdio>
Upvotes: 2