Help me ! I'm dumb!

Posts you want to find years later go here.
Dave
Tenth Dan Procrastinator
Posts: 3483
Joined: Fri Jul 18, 2003 3:40 pm

Help me ! I'm dumb!

Post 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
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 »

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 »

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 »

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 »

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 »

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 »

aren't the Danish white?
Have you clicked today? Check status, then: People, Jobs or Roads

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post 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.

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

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 »

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.
Have you clicked today? Check status, then: People, Jobs or Roads

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

<vinny>
PERELELRllll!!!!11
</vinny>

VLSmooth
Tenth Dan Procrastinator
Posts: 3055
Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:

Post 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 ^^;
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 »

Oh, and yes, perl closes the filehandle LIST for me, so don't worry 8)

Dave
Tenth Dan Procrastinator
Posts: 3483
Joined: Fri Jul 18, 2003 3:40 pm

Post by Dave »

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 »

Just give up and play FFXI
Image

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post 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.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post 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.

Dave
Tenth Dan Procrastinator
Posts: 3483
Joined: Fri Jul 18, 2003 3:40 pm

Post by Dave »

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 »

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 »

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.

Post Reply