Bitcoin Forum
December 04, 2016, 04:36:35 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [Completed Transaction]Newbie C++ help [2BTC] Bounty  (Read 884 times)
CatsLikeToStretch
Newbie
*
Offline Offline

Activity: 26


View Profile
April 01, 2012, 03:20:10 PM
 #1

I am trying to teach myself C++ and I am stuck on something.  I am trying to write a program that writes a series of image files (in .pbm format).  I want the files to be named based on the value of an integer variable.  For example, if the variable contains the value 1045 then I want to output data to a file called 1045.pbm.  I will pay you 1/2 of the bounty if you supply code that works and I'll pay the other half for explaining to me, in terms that a complete beginner like myself, what the purpose of the various bits are code are.  Thanks in advance.  

If you don't believe I will actually pay - you can check https://bitcointalk.org/index.php?topic=73989.0 on the beginner board where I have already paid out for help.  Thanks in advance.
1480869395
Hero Member
*
Offline Offline

Posts: 1480869395

View Profile Personal Message (Offline)

Ignore
1480869395
Reply with quote  #2

1480869395
Report to moderator
1480869395
Hero Member
*
Offline Offline

Posts: 1480869395

View Profile Personal Message (Offline)

Ignore
1480869395
Reply with quote  #2

1480869395
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Matoking
Sr. Member
****
Offline Offline

Activity: 352

Firstbits: 1m8xa


View Profile WWW
April 01, 2012, 04:16:35 PM
 #2

What IDE are you using at the moment? (I use Qt Creator, for an example, some others I can recall from the top of my head are Microsoft Visual Studio and Code::Blocks)

The content of the .pbm files don't have to be anything specific, if I'm correct?

BTC : 1CcpmVDLvR7DgA5deFGScoNhiEtiJnh6H4 - LTC : LYTnoXAHNsemMB2jhCSi1znQqnfupdRkSy
Bitcoin-otc
BitBin - earn bitcoins with your pastes!
CatsLikeToStretch
Newbie
*
Offline Offline

Activity: 26


View Profile
April 01, 2012, 04:20:53 PM
 #3

I am using geany.  I am running ubuntu 10.04. 

Quote
The content of the .pbm files don't have to be anything specific, if I'm correct?

I am writing data to each of the files.  I am trying to generate a series of images, and the name of the image files should be based on the value of an integer variable in the code.
yogi
Legendary
*
Offline Offline

Activity: 947


Hamster ate my bitcoin


View Profile
April 01, 2012, 04:30:33 PM
 #4

#include <sstream>

std::string GenFileName(int i)
{
  std::stringstream out;
  out << i << ".pbm";
  return out.str();
}

Matoking
Sr. Member
****
Offline Offline

Activity: 352

Firstbits: 1m8xa


View Profile WWW
April 01, 2012, 05:02:46 PM
 #5

Code:
#include <iostream>
#include <fstream> // Required, so we can use ofstream
#include <sstream> // Required, so we can use std::stringstream

using namespace std;

int main()
{
    // For statement for looping 10 times
    for(int i=1; i<=10; i++)
    {
        // Tell the user what file number we are working with
        cout << "File number: " << i << endl;

        // Create  a ofstream, which can be used to write into files
        ofstream file;

        // Create a std::stringstream, to which we can input information
        std::stringstream stream;

        // Input the filenumber and the file type to the stream
        // For example, if the value of i was 5, the content of stream would be "5.pbm"
        stream << i << ".pbm";

        // This looks ugly, the stream is converted into std::string, which is converted into char*, which is needed for this function,
        // because it won't accept std::stringstream or std::string types
        file.open(stream.str().data());

        // Warn the user if the file couldn't be opened
        if (file.is_open() == false)
            cout << "Couldn't open the file\n";

        // Define the file is a PBM (portable bitmap) with a magic number
        file << "P1\n";

        // Define the width and height of the image ( width is 6 and height is 4 )
        file << "6 4\n";

        // Let's input the actual data ( \n is used to mark new lines )
        file << "1 0 1 0 1 0\n";
        file << "1 1 1 0 1 0\n";
        file << "1 1 1 0 1 0\n";
        file << "1 0 1 0 1 0";

        // Save and close the file
        file.close();
    }

    // Informs the program has executed successfully and will now close
    return 0;
}

This program should create ten .pbm files.

I'll have to admit I'm not very familiar with std, so the file.open(stream.str().data()) portion could be probably done in a better way.

BTC : 1CcpmVDLvR7DgA5deFGScoNhiEtiJnh6H4 - LTC : LYTnoXAHNsemMB2jhCSi1znQqnfupdRkSy
Bitcoin-otc
BitBin - earn bitcoins with your pastes!
CatsLikeToStretch
Newbie
*
Offline Offline

Activity: 26


View Profile
April 01, 2012, 06:48:36 PM
 #6

Quote
file.open(stream.str().data());

Thats the bit I couldn't get right before.  Thanks for your help and explanation.  2.0001 BTC were just sent to

1M8Xa6crWwrymzUayCML1MJGqjF4JdGHHx  They should show up in the next bock.

Thanks for your help.
Matoking
Sr. Member
****
Offline Offline

Activity: 352

Firstbits: 1m8xa


View Profile WWW
April 01, 2012, 06:52:31 PM
 #7

Thanks very much. Smiley

BTC : 1CcpmVDLvR7DgA5deFGScoNhiEtiJnh6H4 - LTC : LYTnoXAHNsemMB2jhCSi1znQqnfupdRkSy
Bitcoin-otc
BitBin - earn bitcoins with your pastes!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!