Hi, am trying to Write a C++ program to create a data file with several attributes. Accept n person’s information and display the same.
So far this is what I have tried to do. My chaalenge is how to read the command line ipnut from the user to the file

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("Data_file2.txt");
  if (myfile.is_open())
  {
    myfile << "S.No:.\t\t";
    myfile << "Name:.\t\t";
    myfile << "Age:\t\t";
    myfile.close();
  }
  else cout << "Unable to open file";
  
  cout<< "Enter the SNo:"
  cin<<
  

ifstream OpenFile("Data_file2.txt");
char ch;
while(!OpenFile.eof())
{
OpenFile.get(ch);
cout << ch;
}
OpenFile.close();

system("PAUSE");

return 0;
}

Can someone solve my puzzle?

Check this out:

int main()
{
    std::cout << "Enter something: ";

    std::string input;
    std::cin >> input;

    std::cout << std::endl << "Thank you, I will store it in a file now." << std::endl;

  ofstream myfile ("Data_file2.txt");
  if (myfile.is_open())
  {
    myfile << input + "\t\t";
    myfile.close();
  }
  else cout << "Unable to open file";
    
}

Let me know if it helped, please :)

Edited 6 Years Ago by Excizted: n/a

Håhåh if that's his attempt to create a keylogger he will fail. I don't think he's doing that :)

This article has been dead for over six months. Start a new discussion instead.