⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg2_2.cpp

📁 经典数据结构书籍 数据结构C++语言描述 的源代码 很难找的哦
💻 CPP
字号:
#include <iostream.h>
#include <fstream.h>
#include <strstream.h>
#include <stdlib.h>
#include <string.h>

void main(void)
{
    // input text file containing names and values
    ifstream fin;
    
    // read identifiers into name and write results to outputstr
    char name[30], outputstr[256];
    
    // declare an array-based output stream that uses outputstr
    ostrstream outs(outputstr, sizeof(outputstr));
    
    double value;
    
    // open 'names.dat' for input. make sure it exists.
    fin.open("names.dat", ios::in | ios::nocreate);
    if (!fin)
    {
        cerr << "Could not open 'names.dat'" << endl;
        exit(1);
    }
   
   // read names and values. write to outs as 'name = value   ' 
    while(fin >> name)
    {
        fin >> value;
        outs << name << " = " << value << "   ";
    }
    // null-terminate the output string
    outs << ends;
    
    cout << outputstr << endl;
}

/*
<File "names.dat">

start   55
breakloop   225.39
stop    23

<Run of Program 2.2>

start = 55   breakloop = 225.39   stop = 23
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -