Posts you want to find years later go here.
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Thu Feb 05, 2004 7:43 pm
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
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 7:54 pm
Flush your output with endl?
Or else do some method with fout.
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Thu Feb 05, 2004 8:00 pm
adding an endl didnt do anything. and what other method?
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 8:03 pm
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?
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Thu Feb 05, 2004 8:10 pm
nope, ndadaadada. you're white you must know!
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 11:18 pm
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.
quantus
Tenth Dan Procrastinator
Posts: 4891 Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA
Post
by quantus » Thu Feb 05, 2004 11:25 pm
aren't the Danish white?
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 11:27 pm
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.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 11:27 pm
quantus wrote: aren't the Danish white?
You've got them confused with the French.
quantus
Tenth Dan Procrastinator
Posts: 4891 Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA
Post
by quantus » Thu Feb 05, 2004 11:38 pm
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.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Thu Feb 05, 2004 11:56 pm
<vinny>
PERELELRllll!!!!11
</vinny>
VLSmooth
Tenth Dan Procrastinator
Posts: 3055 Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:
Post
by VLSmooth » Fri Feb 06, 2004 3:09 am
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 ^^;
Last edited by
VLSmooth on Fri Feb 06, 2004 3:14 am, edited 1 time in total.
VLSmooth
Tenth Dan Procrastinator
Posts: 3055 Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:
Post
by VLSmooth » Fri Feb 06, 2004 3:10 am
Oh, and yes, perl closes the filehandle LIST for me, so don't worry
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Fri Feb 06, 2004 3:51 pm
nothing worked! you all suck!
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.
Alan
Veteran Doodler
Posts: 2758 Joined: Fri Jul 18, 2003 2:32 am
Location: Where I am
Contact:
Post
by Alan » Fri Feb 06, 2004 4:38 pm
Just give up and play FFXI
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Fri Feb 06, 2004 5:03 pm
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.
Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790 Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA
Post
by Peijen » Fri Feb 06, 2004 6:23 pm
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.
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Fri Feb 06, 2004 6:30 pm
yep, fuzzy to the wescue.
how dare everyone else miss that horrible coding scheme.
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.
Jonathan
Grand Pooh-Bah
Posts: 6722 Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:
Post
by Jonathan » Fri Feb 06, 2004 6:40 pm
I said:
Dwindlehop wrote: Are you sure davezstring has the right value after you exit the loop?
I thought you checked!
Dave
Tenth Dan Procrastinator
Posts: 3483 Joined: Fri Jul 18, 2003 3:40 pm
Post
by Dave » Fri Feb 06, 2004 6:48 pm
I deeeeeeeeeeeeed I deeeeeeeeeeed! I taught i saw a NULLY CAT!
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.