i have a little problem on writing the string into a file, How can i write the string into the file and able to view it as ascii text? because i am able to do that when i set the default value for str but not when i enter a str data Thanks.
#include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { fstream out("G://Test.txt"); if(!out) { cout << "Cannot open output file.\n"; return 1; } char str[200]; cout << "Enter Customers data seperate by tab\n"; cin >> str; cin.ignore(); out.write(str, strlen(str)); out.seekp(0 ,ios::end); out.close(); return 0; }
std::stringmay not be well designed, but it's your friend.cin >> strwill work just fine ifstris astd::string.