读&从文件写

时间:2010-10-15 19:58:22

标签: c++ file

我想用c ++编写一个程序,提示用户输入包含10条记录的现有文件的文件名,每条记录的长度为12个字符。接下来,程序寻找第6条记录的开头,读取文件中的记录并将它们附加到包含3条记录的现有输出文件的末尾。 谢谢。

2 个答案:

答案 0 :(得分:6)

您可能会觉得这很有用:

#include <iostream>
#include "McDonaldsApplication.h" 

int main()
{
  McDonaldsApplication app;
  string name, dob, pos, ssn;
  std::cout << "Enter your name: " << std::endl;
  std::cin >> name;
  std::cout << "Enter your DOB: " << std::endl;
  std::cin >> dob;
  std::cout << "Enter your SSN: "  << std::endl;
  std::cin >> ssn;
  std::cout << "Enter your desired position (0,1,2): " << std::endl;
  std::cin >> pos;
  std::cout << "Thank you! Your application is being submitted now\n";
  app.setName(name);
  app.setDob(dob);
  app.setSsn(ssn);
  app.setPos(pos);
  app.submit();
}

答案 1 :(得分:2)

由于你实际上没有提出问题(问题以“?”结尾),我将用我选择的语言发布一个与你有意义的半相关实现。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TestConsole
{
 class Program
 {
  /// <summary>
  /// http://www.mcdonalds.com/us/en/careers.html
  /// </summary>
  /// <param name="args"></param>
  static void Main(string[] args)
  {
   using (StreamWriter writer = new StreamWriter("c:\\mcdonalds_app.txt"))
   {
    writer.WriteLine("Hello, my name is {0}. I'd love to work here!", args[0]);
    writer.Close();
   }
  }
 }
}