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?

C++ Forum please.

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 :)

whats line 18 doing?

whats line 18 doing?

Closing int main() hopefully :)

Closing int main() hopefully :)

lol wrong person, sorry for the ambiguity.

sounds like a keylogger to me =\, I could be wrong

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

Since no one has yet even touched on the command line, see this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.