Oto mój kod programu i jest problem, wczytuje plik (plik.txt // przykład na dole), i musze z tych wczytanych liczb uciąć tak żeby zostały ostatnie dwie (mają zostać tylko one), to akurat wiem jak zrobić ale coś kuleje mi zamiana char na int jak by ktoś umiał znaleść babola :)
#include <iostream>#include <iomanip>#include <fstream>#include <string>#include <sstream>using namespace std;const int a=22688;int i=0;struct baza{int psesl;char pesel[a];};baza tab[a];void plik(){string bufor, pesel;int p1, p2;long int licznik=0;ifstream plik;plik.open ("dane.txt", ifstream::in); while (plik.good()){getline(plik,bufor); if (bufor.size() > 0){p1 = bufor.find_first_of(" ");pesel = bufor.substr(0, p1);strcpy(tab[i].pesel,pesel.c_str());istringstream zm(pesel); zm >> tab[i].pesel;i++;licznik++;}}plik.close();}main(){ ofstream plik1;plik1.open ("skrocone.txt", ifstream::in); plik();for (int i=0; i<20; i++){cout << tab[i].pesel << endl;long c = atoi(tab[i].pesel);cout << c << endl;long a = c % 100;cout << a << endl;//c = itoa©;// c >> tab1[i].pesel;// plik1 << tab1[i].pesel << endl;} plik1.close();system("PAUSE");return EXIT_SUCCESS;}
Przykład pliku (dane.txt)