Jump to content

C++ Question


Recommended Posts

    if (std::strcmp(answer, "yes")) {
        std::cout<<"Please stand by while the data is being gathered and the file is being generated...\n";
        std::ofstream outfile("C:/Users/businessman332211/Desktop/test.txt");
        outfile << "This is data." << std::endl;
        outfile.close();
        system("pause");
    }

I had this figured out before, but I stepped away from C++ and I am trying to pick up where I left off.

basically I just want to generate a text file on the desktop...This isn't working even though everything i have read tells me it should

 

Another question..what happens if I want to step out of the C drive and access another drive...for example an External harddrive, or a secondary drive on the same computer?

Link to comment
Share on other sites

Nevermind..it was me using the compare function wrong.

    if (std::strcmp(answer, "yes") == 0) {
        std::cout<<"Please stand by while the data is being gathered and the file is being generated...\n";
        std::ofstream myfile;
        myfile.open("C:/Users/businessman332211/Desktop/example.txt");
        myfile<<"This is data.";
        myfile.close();
        return 0;
    }

That is the right way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.