I have written a C++ as I learn C++ along, and the funny thing is that this C++ I wrote, just have to open a txt file, and reads it and cout the content.
The txt file (new.txt) content is 12345.
But the output that I got once compiled was 123. I can't figure out why 45 doesn't appear. If I revert to char str[12]; it outputs 12345. I dunno what's wrong with my code below:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char *str;
str = new char;
fstream file;
file.getline(st r, sizeof str);
cout << str << endl;
file.close();
}
The txt file (new.txt) content is 12345.
But the output that I got once compiled was 123. I can't figure out why 45 doesn't appear. If I revert to char str[12]; it outputs 12345. I dunno what's wrong with my code below:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char *str;
str = new char;
fstream file;
file.getline(st r, sizeof str);
cout << str << endl;
file.close();
}
Comment