Problem with fstream

Hello i am from Poland, so sorry for my language mistakes.

I have to solve problem with my homework.
Program have to write numbers for exaple "one" if i input 1.
My idea is to create notepad file where i have in first line one in second two etc... Is it possible to do? I think i have to write in first line "1 one" and if in file find input for exaple 1 program getline 1 line. And rewrite it to program.

Can anybody help me?

Please about answer in simple language!
Last edited on
Yes. I would not use files to solve this particular problem.
The easy way to solve this would be to read characters from input with a basic loop, e.g.
1
2
3
4
char n;
while (std::cin >> n) {
    // ...
}

Then, using a switch statement, comparing with all digits 0..9 and write the according digit in "written form", e.g.
1
2
3
4
5
6
7
8
9
switch (n) {
case '0':
    std::cout << "zero";
    break;
// ...
default:
    std::cout << "Please enter digits only.";
}
std::cout << '\n';

If you want to explain a problem and have trouble expressing yourself, try giving examples for input and output:
Input:

1
2
3

Output:

one
two
three

(This is how I understood your problem)
oh.... yes, why I didn't think about case
thank you very much!
Topic archived. No new replies allowed.