-
why wont getline() work?
im working through TICPP one and i cant seem to get getline() to work;
i am actually having a new problem. ive gotten getline to work. i was just reading from the wrong stream. but now i cant seem to get the output in normal text rather then hex?
0x22fdb4 is what i get. when i want to output the whole string
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string msg = "this is a string";
ofstream space_fileA ("spaces.txt");
space_fileA<< msg;
space_fileA.close();
ifstream space_fileB ("spaces.txt");
space_fileB>> msg;
getline(space_fileB, msg);
}
any help at all is appreciated
-
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string msg = "this is a string";
string msg2;
ofstream space_fileA ("spaces.txt");
space_fileA<< msg;
space_fileA.close();
ifstream space_fileB ("spaces.txt");
// space_fileB>> msg;
getline(space_fileB, msg2); // note: B, not A
cout << msg2 << endl;
}