How to use the input and output of a file in a class

Updated on technology 2024-05-13
9 answers
  1. Anonymous users2024-02-10

    I don't bother to check the file operation function.

    In short, define a class first, such as file operate, and then this class should have the file path property.

    There should be two methods, read and write.

    So the format is as follows:

    class file_operate{

    char *path;Path.

    bool read();

    bool writ();

    file_operate(char *fpath) {strcpy(this->path,fpath);The purpose of this sentence is to save the path, so that even if a program changes the contents of the parameter string on the outside, it still does not change the object.

    file_operate()

    Close the file IO stream. Functions forgot.

    Create an object like this: file operate fo= new file operate("c:/");

    In this way, the FO is an operation object for the text document of the C disk file. If you want to read this file, call it; Write calls. If you want to change the file, you can change it to fo->path.

  2. Anonymous users2024-02-09

    It's good to customize a class, referencing the operation class of the file stream in the member function to read and write the file.

  3. Anonymous users2024-02-08

    #include

    #include

    #include

    using namespace std ;

    class employee

    -1 is the largest unsigned integer.

    employee( unsigned int _id, string _name ):id( _id ) name( _name)

    fstream& operator<<(fstream& of, const employee& e )

    fstream& operator>>(fstream& if, employee& e )

    int main()

    The framework is just that, it's not tested. If you feel clumsy with fstream, use ofstream ifstream instead.

  4. Anonymous users2024-02-07

    #include

    #include

    #include

    int a[5],b[1];

    readdat();

    writedat();

    void jssort() defines the function jssort() which is used to calculate the value of the middle value and deposit it into.

    The main() main function performs three steps: input, write, and output.

    readdat() input function.

    writedat() output function fclose(out); }

  5. Anonymous users2024-02-06

    No, you define. h is the header file, the header file only participates in the compilation, not responsible for execution, and should be linked when executing. c is the source file, so your ** should be written in. cout and cin can be executed

  6. Anonymous users2024-02-05

    Bingo can encapsulate this input and output function in the common function of the class.

  7. Anonymous users2024-02-04

    4.Insertion function: It is mainly to facilitate the user to insert information such as date and time.

    5.Font settings: You can set the display font of the device from the [Font] menu, and the font settings should be able to set the font color.

    The font does not need to be saved to a file, i.e. the font settings are only valid for the current time, and do not need to be the same as the last font when exiting the program and running it again.

    6.For implementations in the CeditView class, the corresponding menu item for the file function must not use the following id values:

  8. Anonymous users2024-02-03

    The header files that come with the compiler are included in the include folder of the installation directory, including iostream, math, etch form is fine, and include is used when introduced""<> cannot be used, and this form is recommended in using relative path C++:

    include No. h This is the input/output stream include in front of c as not. h denotes that this is a mathematical function that can be used namespace std after introduction; Here's an example of a namespace file operation to introduce an include file stream:

    #include

    #include

    using namespace std;

    int main() reads and writes files in text form {char ch; }

    cout<<"open file"<

  9. Anonymous users2024-02-02

    In C++, there is no plain text file operation that jumps to "line", and generally outputs a few lines in the order, after sequential reading (getline), if judgment is performed through conditions, the output is selected, and after the specified output is completed, the break ends the loop statement to close the read file.

    A rough example is as follows:

    fclose(fp);

Related questions
13 answers2024-05-13

The game that hasn't been patched.,FSD is really unrecognizable.,I don't know the latest version.,Anyway, it's definitely not recognized.。 So I learned to be obedient later. It's all patched first and then backed up. >>>More

15 answers2024-05-13

Note that the getline function uses a carriage return as a terminator, but it does not take a carriage return into account. in the first, 5); At the end of the end, a carriage return is kept in the cache when executed to the second, 5); The function reads the carriage return that is kept in the cache, and thinks that the read has ended, so the second string of five characters entered after that is not read into ch, of course, ch is empty, and can be used; Solve this problem; Here's how: >>>More

10 answers2024-05-13

To align the table of contents in Word, use the system to automatically generate the table of contents, and select the alignment style. >>>More

6 answers2024-05-13

Hehe, I seem to have been in a similar situation, and I think I can do this problem. Under normal circumstances, taking word as an example, there should be both five numbers and Arabic numerals in the font size selection column, in addition to a detail, after opening word, a Chinese input method is also opened by default, if you often use word2003, I believe you will notice this. But I'm not used to the default opening of the Chinese input method, so I want to see if there are any settings that can be changed. >>>More

15 answers2024-05-13

Create a text file on the desktop, change the suffix to bat, right-click on the file, and type ping ** or ip. Or find the file under the C: Windows System32 folder and send the shortcut to the desktop.