自己乱写的文件输入输出例程 乱到极致 心脏不好的勿入

<pre name="code" class="cpp">/*
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main()
{
    ofstream File1("love.txt");
    File1 << "minho oppa salanghei\n woohyun oppa\nsalanghei";
    File1.close();
    ifstream File("love.txt");
    File.seekg(ios::beg);
    char line[100];
    while(!File.eof())
    {
        File.getline(line,100);
        cout << line << endl;
    }


    File.close();
    return 0;
}
*/
/*
minho oppa salanghei
 woohyun oppa
salanghei

Process returned 0 (0x0)   execution time : 0.429 s
Press any key to continue.

*/
/*
#include<iostream>
#include<fstream>
using namespace std;
int main()
{

    ifstream file("shinee.txt");

    int a[3];
    for(int i=0; i<3; i++)
    {
        file >> a[i];
        cout << a[i] << endl;

    }

    return 0;
}
*/
/*
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ofstream file("fighting.txt");
    int a[4];
    int b[4];
    for(int i=0; i<4; i++)
    {
        cin >> a[i];
        file << a[i] << endl;
    }
    file.close();
    ifstream file1("fighting.txt");
    for(int i=0; i<4; i++)
    {
        file1 >> b[i];
        cout << b[i] << endl;
    }
}
*/
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    int a;
    ofstream file("fighting.txt");

        file << 123;

    file.close();
    ifstream file1("fighting.txt");

        file1 >> a;
        cout << hex << a << endl;

}

#include <fstream>#include<iostream>using namespace std;int main(){ fstream File("test.txt",ios::in | ios::out); File << "Hi! choiminho!"; //将“Hi!”写入文件 ,为什么不识别我家珉豪欧巴呢,因为他太帅了!开玩笑啦!因为空格呦。 ///static char str[10]; //当使用static时,数组会自动被初始化 //即是被清空为零 ifstream OpenFile("test.txt"); File.seekg(ios::beg); // 回到文件首部 // 此函数将在后面解释 File >> str; cout << str << endl; File.close(); return 0;}*/
 


 
/*
#include <fstream>
#include<iostream>
using namespace std;
int main()
{
    fstream File("test.txt",ios::in | ios::out);

    File << "Hi!choiminho!\ndfhsajfk dskfaj\n fafsaaajf"; //将“Hi!”写入文件
    ///static char str[10]; //当使用static时,数组会自动被初始化
               //即是被清空为零
*/
  /*  File.seekg(ios::beg); // 回到文件首部
                  // 此函数将在后面解释
    ifstream OpenFile("test.txt");
    char str[30]; //每个单词的长度不能超过30个字符
    while(!OpenFile.eof())
    {
       OpenFile >> str;
       cout << str << endl;
    }
    */
/*
    ifstream OpenFile("test.txt");
    File.seekg(ios::beg); // 回到文件首部
                  // 此函数将在后面解释

    char line[100]; //每个整行将会陆续被存储在这里
    while(!OpenFile.eof())
    {
        OpenFile.getline(line,100); // 100是数组的大小
        cout << line << endl;
    }

    File.close();
    return 0;
}
*/
/*
单词:
Hi!choiminho!
dfhsajfk
dskfaj
fafsaaajf

Process returned 0 (0x0)   execution time : 0.583 s
Press any key to continue.

*/

/*
整行读取:
Hi!choiminho!
dfhsajfk dskfaj
 fafsaaajf

Process returned 0 (0x0)   execution time : 0.620 s
Press any key to continue.

*/
/*
小科普:
exit(0)与exit(1)、return区别

exit(0):正常运行程序并退出程序;

exit(1):非正常运行导致退出程序;

return():返回函数,若在主函数中,则会退出函数并返回一值。

详细说:

  1. return返回函数值,是关键字;  exit 是一个函数。

  2. return是语言级别的,它表示了调用堆栈的返回;而exit是系统调用级别的,它表示了一个进程的结束。
  3. return是函数的退出(返回);exit是进程的退出。

  4. return是C语言提供的,exit是操作系统提供的(或者函数库中给出的)。

  5. return用于结束一个函数的执行,将函数的执行信息传出个其他调用函数使用;exit函数是退出应用程序,
  删除进程使用的内存空间,并将应用程序的一个状态返回给OS,这个状态标识了应用程序的一些运行信息,这
  信息和机器和操作系统有关,一般是 0 为正常退出, 非0 为非正常退出。

  6. 非主函数中调用return和exit效果很明显,但是在main函数中调用return和exit的现象就很模糊,多数情
  况下现象都是一致的。
*/
/*
#include<fstream>
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    ofstream SaveFile("minho.txt");
    SaveFile << "minho oppa maoxida!";

    if (!SaveFile)
    {
    cout << "Error opening the file! Aborting…/n";
    exit(1);
    }
    return 0;
}
*/
/*
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    fstream file1;
    file1.open("shinee.txt");

    file1 << hex <<123;

    return 0;
}
*/
/*
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    fstream file1;
    file1.open("shinee.txt");
    int i;
    file1 >> i;

    file1 << hex <<123;

    return 0;
}
*/
/*
shinee的变化:
15 16
7b5 16

15 16
15 7b
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值