ofstream

Is there a way to display all saved objects in vector classes?

一曲冷凌霜 提交于 2020-05-17 05:47:12
问题 I coded this for a bus system but having trouble displaying the objects that have been saved in stud1 . I tried using readData but didn't work. The purpose of the code is to 1. receive input(s) in the form of bus info from the user and save them and 2. output all buses input into the system(reposted altered code) #include <iostream> #include <fstream> #include <vector> using namespace std; string busType, busMake, regNum; char menu(); int id = 0; //int staff[50]; int carObjNum, option0; int

C++: cin >> *char

浪尽此生 提交于 2020-04-13 17:23:35
问题 So, I'm currently writing a line editor as a learning project on I/O, writing files, and the like. It is written in C++, and I am currently trying to write out to a file of the user's choosing. I have CLI arguments implemented, but I currently have no idea how to implement an in program way of specifying the file to write to. char *filename; if (argc >= 2){ filename = argv[1]; } else{ cout << "file>"; cin >> filename; cin.ignore(); } This works perfectly well when I use command line arguments

Insert instance of ofstream to container

孤街醉人 提交于 2020-01-30 12:15:45
问题 I created my a class file which is a wrapper for std::ofstream . I created a Container to contain all the instances of file . class file { private: std::ofstream ofs; public: void open(std::string filename); void write(std::string s); void close(); }; class Container { private: std::map<int, file> m; public: void insert(file f,int i) { m.insert(std::pair<int,file> (i,f)); } void get(int i) { m.at(i); } }; However, there is an issue in this code. In the insert method I am attempting to copy a

Insert instance of ofstream to container

假如想象 提交于 2020-01-30 12:15:28
问题 I created my a class file which is a wrapper for std::ofstream . I created a Container to contain all the instances of file . class file { private: std::ofstream ofs; public: void open(std::string filename); void write(std::string s); void close(); }; class Container { private: std::map<int, file> m; public: void insert(file f,int i) { m.insert(std::pair<int,file> (i,f)); } void get(int i) { m.at(i); } }; However, there is an issue in this code. In the insert method I am attempting to copy a

Remove parts of text file C++

こ雲淡風輕ζ 提交于 2020-01-30 03:29:51
问题 I have a text file called copynumbers.txt that I need to delete some numbers after a number while using Example would be a text file containing the following 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 each integer should occupy 4 byte spaces. I want to delete or get rid of number 7 to 15 while keeping 1 through 6 then adding the number 30 to it. so then the file would keep 1 to 6 and get rid of 7 to 15 then after that I want to at 30 at the end of it. my new file should look like this 1 2 3 4 5 6 30

C++ ofstream line break

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-29 12:19:34
问题 This is my code: #include <iostream> #include <fstream> using namespace std; int main() { ifstream ifile ("input.dat", ios::in); ofstream ofile ("output.dat",ios::out); int num; ifile >> num; ofile << num; ofile << endl; ofile << "Did we go to new line?"; ofile << endl; return 0; } The problem is, everything in output.dat is on the same line. How can I resolve this? Thanks! EDIT: I was using Windows to see the files and Linux to compile. This is why I was running into this issue. Using cat

C++ ofstream line break

杀马特。学长 韩版系。学妹 提交于 2020-01-29 12:18:47
问题 This is my code: #include <iostream> #include <fstream> using namespace std; int main() { ifstream ifile ("input.dat", ios::in); ofstream ofile ("output.dat",ios::out); int num; ifile >> num; ofile << num; ofile << endl; ofile << "Did we go to new line?"; ofile << endl; return 0; } The problem is, everything in output.dat is on the same line. How can I resolve this? Thanks! EDIT: I was using Windows to see the files and Linux to compile. This is why I was running into this issue. Using cat

C++ ofstream line break

▼魔方 西西 提交于 2020-01-29 12:18:33
问题 This is my code: #include <iostream> #include <fstream> using namespace std; int main() { ifstream ifile ("input.dat", ios::in); ofstream ofile ("output.dat",ios::out); int num; ifile >> num; ofile << num; ofile << endl; ofile << "Did we go to new line?"; ofile << endl; return 0; } The problem is, everything in output.dat is on the same line. How can I resolve this? Thanks! EDIT: I was using Windows to see the files and Linux to compile. This is why I was running into this issue. Using cat