C++ - inserting images into files

Status
Not open for further replies.

C++

Junior Member level 3
Joined
Oct 12, 2004
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
243
code for inserting image in dev c++

Hi, I've got a simple command line program like this:

Code:
#include <iostream>
#include <fstream>

using namespace std;

int main () {

    ofstream file;
    file.open ("Test.doc");

    file << "This is an image inserted into this file with C++!" << endl;

    // Somehow insert an image below that line <-- dont know how

    file << "This line was inserted after the image!";

    file.close ();

    cout << "Press ENTER to exit . . .";    
    cin.get ();
    
    return 0;
}

What code can I put into that commented line to insert the picture into that file?

Any help is appreciated....

Platform: Windows (XP)
Compiler: Dev-C++/MSVC++
 

Re: C++ - inserting images into files . . .

If your using a DOC file (ie., Microsoft Word) then I think the definition of the format is available. You might be able to find out how to create a DOC file here http://www.wotsit.org/.

- Jayson
 

that wasn't really helpful, when i write to the file like that, it saves it as plain text, but it can still support advanced features since it's a .doc file

i just need some function to copy and paste a picture in the file
 

The easiest way to acomplish this could be using OLE Automation ...

You can use this VB code to figure C++ code using automation

Code:
    Selection.InlineShapes.AddPicture FileName:= _
        "D:something.jpg", LinkToFile:=False, SaveWithDocument:=True
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="This image was inserted ...."
    ActiveDocument.Save
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…