use qt c++ set manual location and create file -


i start study c++ , been try set manual location create file, got trouble here.

do have idea solve problem??

int main() {     char location;     std::cin>>location;     qfile file("location");     if (!file.open(qiodevice::writeonly | qiodevice::text))         return 1;     qtextstream out(&file);     out << "the magic number is: " << 49 << "\n"; } 

other answers have picked on issues. i'd point out can use qt's text streams access standard input , standard output, keep qt. helps executable size if you'd link project statically - don't need link-in c++ streams nor string.

#include <qfile> #include <qstring> #include <qtextstream> #include <cstdio>  int main() {     qtextstream in(stdin), out(stdout); // input , output streams, qt way     out << "enter file location: " << flush;     qstring location = in.readline(); // should store file location     qfile file(location);     if (!file.open(qiodevice::writeonly | qiodevice::text))         return 1;     qtextstream fout(&file);     fout << "the magic number is: " << 49 << "\n";     return 0; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -