Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
View Poll Results: C++:Why I can’t open this PDF file created by this C++ program ?
C++:Why I can’t open this PDF file created by this C++ program ? 1 100.00%
C++:Why I can’t open this PDF file created by this C++ program ? 0 0%
Voters: 1. You may not vote on this poll

  #1 (permalink)  
Old October 29th, 2011, 09:55 AM
Registered User
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default C++:Why I can’t open this PDF file created by this C++ program ?

C++:Why I can’t open this PDF file created by this C++ program ?

This originally is a simple example used in Larry’s book ,now I changed "std::ofstream fileOutput("quotes.txt ", std::ios::app);" to " std::ofstream fileOutput("quotes.pdf ", std::ios::app);" so as to creat a PDF file (I think !!!), When I compile and run using Dev C++ on Windows XP, it certainly created a quotes.pdf file,but I was not able to open it with Adobe reader , every time when I try to open it ,The Adobe reader always shows that “Adobe Reader couldn’t open “quotes.pdf”,because it is either not a supported file type or because the file has been damaged (for example ,it was sent as an email attachment and wasn’t correctly decoded )”,so what’s wrong here ? Can anyone help me with this?

// quote2.cpp - Script 4.8

// We need the iostream file in order
// to use cout and cin.
#include <iostream>

// We need the string file
// for the string functionality.
#include <string>

// We need the fstream file in order
// to work with files.
#include <fstream>

// Start the main function.
int main() {

// Declare the necessary variables.
std::string quote, speaker;

// Prompt the user for the quotation.
std::cout << "Enter a quotation (without quotation marks):\n";
std::getline(std::cin, quote);

// No extraneous input to be discarded
// because all input is assigned to the string!

// Prompt the user for the quotation's author.
std::cout << "Enter the person to whom this quote is attributed:\n";
std::getline(std::cin, speaker);

// Create a blank line in the output.
std::cout << "\n";

// Repeat the input back to the user.
std::cout << "The following quote has been received...\n\n"
<< quote << "\n-" << speaker << "\n\n";

// Write the data to the file.

// Define a file object.
std::ofstream fileOutput("quotes.pdf", std::ios::app);

// If the file is open, record the data.
if (fileOutput.is_open()) {

// Write the data to the file.
fileOutput << quote << "|"
<< speaker << "\n";

// Close the stream.
fileOutput.close();

// Print a message.
std::cout << "The data has been written to the file!\n";

} else { // Couldn't open the file.
std::cout << "The file could not be opened!\n";
return 1; // Indicates a problem occurred.
}

// Wait for the user to press Enter or Return.
std::cout << "Press Enter or Return to continue.\n";
std::cin.get();

// Return the value 0 to indicate no problems.
return 0;

} // End of the main() function.
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Launching a program/open a file through VBA biglazy Access VBA 3 February 28th, 2006 04:30 PM
open a formatted excel file from program darvarin C++ Programming 1 June 15th, 2005 03:24 AM
open a pdf file viren_balaut J2EE 0 January 26th, 2004 10:50 PM
open a pdf file viren_balaut Servlets 0 January 24th, 2004 01:03 AM
open a pdf file in browser viren_balaut Pro JSP 0 January 12th, 2004 01:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.