Page 1 of 3

Help me ! I'm dumb!

Posted: Thu Feb 05, 2004 7:43 pm
by Dave
Im trying to read strings from a text file as the name for an output file, but so far nothing is actually created.

input: inputstrings.txt
outputfile name in inputstrings.txt : wtf.txt
=================================
Code:

string davezstring;
ifstream ffff("stringinputs.txt");
while(ffff>>davezstring)
{
cout << "ok!\n";
cout << davezstring <<endl;
cout << davezstring.c_str() <<endl;
}
ffff.close();

ofstream fout(davezstring.c_str());
fout << "123!@#123!@#'1@31";

=================================

I also tried

FILE *teststream;
teststream = fopen(davezstring.c_str(), "w");
fprintf( teststream, "jhdgasjdh&*#@^*#&@" );
fclose( teststream );

and no soup

Posted: Thu Feb 05, 2004 7:54 pm
by Jonathan
Flush your output with endl?
Or else do some method with fout.

Posted: Thu Feb 05, 2004 8:00 pm
by Dave
adding an endl didnt do anything. and what other method?

Posted: Thu Feb 05, 2004 8:03 pm
by Jonathan
Are you sure davezstring has the right value after you exit the loop?

I dunno, .close() or something. Do I look like a C++ expert to you?

Posted: Thu Feb 05, 2004 8:10 pm
by Dave
nope, ndadaadada. you're white you must know!

Posted: Thu Feb 05, 2004 11:18 pm
by Jonathan
You got the polarity wrong. You're Asian, you must know.

Actually, neither of us knows, but I bet I know who does. The Danish! Let's ask Stroustrup.
std::ofstream to(argv[2]);
if (!to) error ("cannot open output file", argv[2]);
Bjarne says to test your ofstream to see if it's not NULL before you do anything with it.

Posted: Thu Feb 05, 2004 11:25 pm
by quantus
aren't the Danish white?

Posted: Thu Feb 05, 2004 11:27 pm
by Jonathan
Bjarne also says
bool is_open() const;
void open(const char* p, openmode m = out);
void close();
I think Bjarne wants you to .close() that bad boy.

Posted: Thu Feb 05, 2004 11:27 pm
by Jonathan
quantus wrote:aren't the Danish white?
You've got them confused with the French.

Posted: Thu Feb 05, 2004 11:38 pm
by quantus
So, ummm, what are you trying to do anyway and why not just use perl? I'm gonna go walk away now while vinny expounds the greatness of perl.

Posted: Thu Feb 05, 2004 11:56 pm
by Jonathan
<vinny>
PERELELRllll!!!!11
</vinny>

Posted: Fri Feb 06, 2004 3:09 am
by VLSmooth

Code: Select all

#!/usr/bin/perl -w                     # tells shell to use perl with warnings

sub do_stuff() {                       # subroutine
  print CURRENT "whee!\n";             # that prints "whee!\n" to CURRENT
}



open LIST, "filelist.txt" or die $!;   # opens the file list

while (<LIST>) {                       # iterates over the file list
  open CURRENT, ">$_" or die $!;       # opens a writeable output file
  do_stuff();                          # does the stuff you want to the file
  close CURRENT;                       # closes the current output file
}

print "$0 done!\n";                    # tells you you're done
Btw, this took <5 minutes to write and test on my home box ^^;

Posted: Fri Feb 06, 2004 3:10 am
by VLSmooth
Oh, and yes, perl closes the filehandle LIST for me, so don't worry 8)

Posted: Fri Feb 06, 2004 3:51 pm
by Dave
nothing worked! you all suck!

Posted: Fri Feb 06, 2004 4:38 pm
by Alan
Just give up and play FFXI

Posted: Fri Feb 06, 2004 5:03 pm
by Jonathan
Dave wrote:nothing worked! you all suck!
i think the source of suckage is you!

maybe your thingy doesn't have a valid filename. or maybe it's creating a file in a different place from where you're looking.

Posted: Fri Feb 06, 2004 6:23 pm
by Peijen
I could be wrong, but doesn't

while (ffff>>davezstring) {}

perform one additional read after the end of file? I am not sure if that affects your shit or not.

Posted: Fri Feb 06, 2004 6:30 pm
by Dave
yep, fuzzy to the wescue.

how dare everyone else miss that horrible coding scheme.

Posted: Fri Feb 06, 2004 6:40 pm
by Jonathan
I said:
Dwindlehop wrote:Are you sure davezstring has the right value after you exit the loop?
I thought you checked!

Posted: Fri Feb 06, 2004 6:48 pm
by Dave
I deeeeeeeeeeeeed I deeeeeeeeeeed! I taught i saw a NULLY CAT!