String to Character

I have a text file which contains ASCII of A,B and C like below,
65
66
67
Now I need to create a file which containing letters related with above ASCII like below,
ABC

Problem is with conversion... Can any one help me..
This is my code.

#include<iostream>
#include<fstream>
#include<string>
#include<numeric>
using namespace std;

int main()
{
ifstream ipf;
ofstream opf;
string line;
int c;
char x;
ipf.open("ASCII.txt",ios::in|ios::binary);
opf.open("Character.txt",ios::app);

while(getline(ipf,line))
{
cout<<line<<endl;
c =accumulate(line.begin(),line.end(),0);
x = static_cast<char>(c);
opf<<x;
}
ipf.close();

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>

int main()
{
    // open the input file as plain text
    std::ifstream input_file( "ASCII.txt" ) ;

    // open the output file to write plain text
    std::ofstream output_file( "Character.txt" ) ;

    int number ;
    while( input_file >> number ) // for each number read from the input file
    {
        char c = number ; // convert it to a char (we blindly assume that the encoding is ascii)
        output_file << c ; // and write the character to the output file
    }

    output_file << '\n' ; // decency demands that we end the output with a new line
}
Thank you very much. You solved my problem... :)
Last edited on
Topic archived. No new replies allowed.