example199.cpp
来自「Data Abstraction & Problem Solving with 」· C++ 代码 · 共 43 行
CPP
43 行
#include <iostream>#include <fstream>#include <string>using namespace std;struct Node{ int item; Node *next;}; // end structint main(){ Node *head = NULL; head = new Node; head->item = 1; Node *p = head; for (int i=2; i<=5; i++) { p->next = new Node; p = p->next; p->item = i; } p->next = NULL; // Saves a linked list's data in a text file of // integers; head points to the linked list. string fileName = "numbers.txt"; // fileName is a string that names an external text // file to be created ofstream outFile(fileName); // traverse the list to the end, writing each item for (Node *cur = head; cur != NULL; cur = cur->next) outFile << cur->item << endl; outFile.close(); // Assertion: The text file contains the linked // list抯 data in its original order. return 0;} // end main
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?