The program I'm writing is suppose to ask the user for name, haircolor, age and weight and these are then placed in a struct. The struct is then written to a file 'REGISTER.TXT' among other heroes.
I'm using three separate files of main.cpp, hero.h and hero.cpp where the latter holds the current functions.
** Main Issue: The struct writes korean characters instead of 'A - Z'. This is interesting in this case because I have a totally separate program with the same ofstream-code, the only difference is that the code below is in separate files and the working program is all written in one single file.
#include <iostream>
#include <vector>
#include <fstream>
#include "hero.h"
// Struct heroes as parameter to function new_hero
void new_hero(heroes & myHero)
{
heroes strukt;
std::cout << '\n' << "Ange din hjältes namn: ";
std::cin >> strukt.name;
std::cout << "Din Hero har nu namnet: "
<< strukt.name << std::endl;
std::cout << "Ange hårfärg: ";
std::cin >> strukt.haircolor;
std::cout << "Hårfärgen på din Hero är: "
<< strukt.haircolor << std::endl;
std::cout << '\n';
std::cout << "Ange ålder: ";
std::cin >> strukt.age;
std::cout << "Din Hero's ålder: " << strukt.age
<< std::endl;
std::cout << '\n';
std::cout << "Ange din Hero's vikt: ";
std::cin >> strukt.weight;
std::cout << "Din Hero's vikt är: " << strukt.weight << std::endl;
std::cout << std::endl;
std::cout << "Ange din Hero's kön: ";
std::cin >> strukt.sex;
std::cout << "Din Hero är en: " << strukt.sex << std::endl;
// Writing the heroes name from Struct to REGISTER.TXT
std::ofstream utdata;
utdata.open("/Users/username/C++ projects/Stream IO File/Stream IO
File/REGISTER.TXT", std::ios::app);
utdata << strukt.name;
utdata.close();
};
I can of course include the header-file and main.cpp if anyone asks, but if you can spot something wrong right away that would be great.