Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

_Jonny

Problems with ofstream

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so I have a program that when you drag files onto, it prints them out on the screen. I got this part down, and it works perfectly. The part that I am having a problem with is the ofstream part. I can''t make it so the program also writes them to a file. Let''s say I drag the file "hello.txt" onto my program. It does it''s job by printing the filename onto the screen, but it seems to skip the part where it rights the file name to the file. Anybody know what my problem is? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The problem is quite obviously line 18 of print.cpp, the if statement misses out the writing to the outfile.

Share this post


Link to post
Share on other sites
I can''t tell if that is a serious response or not... are you trying to say that you need to see that code? In that case:

int
main (int argc, char *argv[])
{
char the_file[255];
strcpy(the_file, argv[1]);

ofstream file ("list.txt");
file << the_file << "\n";
file.close();

cout << the_file << "\n";
system("pause");
return 0;
}

That help?

Share this post


Link to post
Share on other sites
try this.. when using << or >> operators you should use strings, not char arrays...


#include <iostream>
#include <stdlib.h> // system()

#include <fstream> // ofstream

#include <string> // std::string

using namespace std;

main(int argc, char *argv[]) {

std::string the_file;
the_file = argv[1];

ofstream file("list.txt");
if(!file.is_open()) cout << "\nError Opening File.." << endl;

file << the_file << endl;
file.close();

cout << the_file << endl;
system("pause");
return 0;

}


[edited by - tonic151 on February 29, 2004 3:00:49 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!