Input/Output

It's been a while since I have been here. This is very basic, I need a way to open a file, read only one character, perform math operation, output new char in new file, move on to the next char and repeat. How would I do this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int main() {
fstream file;
const char* filename;
file.open(filename);
a:
(Get first char)
(Math ops)
(Write new char to new file)
goto a;
}
If your file isn't whitespace delimited, you can do:
1
2
3
4
5
6
7
std::ifstrem input(filename);
std::ofstream output(name_of_file);
char c;
while(input.get(c)){
    //perform op
    output << c;
}
You can do that? I have to do a little reading for a minute or two.
whitespace delimited


Unsure what this means... I'm a bit of a beginner in I/O.
Is your input file looks like
asdfghle
or
a s d f
g h l e
and should whitespaces be read and processed
Last edited on
The input file, when opened in notepad will have whitespaces and no whitespaces. Whitespaces MUST be processed or else it will not work.
So my code is fine. (and by whitespaces I meant also newlines and tabulation)
Thanks but it seems I have stumbled upon a new issue. I'm going to try something and if it doesn't work, I'll tell you.

(EDIT) Didn't work. When I attempt to run the program, the input file pulls a fail(). No idea what's wrong.

if (infile.fail() == 1) (cout<< "Fail.\n");

When does this usually happen?

(EDIT2) I got half of it working. It wont read the input file but it opens the output file just fine.

(EDIT3) It opens the input and output file, but now it passes fail() for the input and writes: ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ

in the output file. explanation??
Last edited on
Topic archived. No new replies allowed.