Question

I need a method created in C++ linux that follows the following header file and requirements.

* Parameters * path character string provides a location to download the attached file * Returns: true if attachment successfully written, false otherwise. bool Downloa dattachnent(const char*p ath const;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

testfile.h

class testfile{
public:
bool DownloadAttachment(const char* path="") const;
};

download attachment.cc

#include "testfile.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool testfile::DownloadAttachment(const char* path) const{
cout<<path<<endl;
ifstream infile(path);
string s=path;

if(infile.good()){
cout<<"exists"<<endl;
return true;
}else{
cout<<"not exists"<<endl;
unsigned foundAt = s.find_last_of("/\\");
// cout<<s.substr(0,foundAt)<<endl;
// cout<<s.substr(foundAt+1)<<endl;

const char* originalFilename=s.substr(foundAt+1).c_str();
ofstream inf(originalFilename);
if(inf){
return true;
}

}
return false;
}

int main(){
testfile t;
cout<<t.DownloadAttachment("/home/gopal/installation.pdf")<<endl;;

}

Add a comment
Know the answer?
Add Answer to:
I need a method created in C++ linux that follows the following header file and requirements....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any pa...

    c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....

  • 1. Assume the following struct is declared for the permission list of a file in Linux....

    1. Assume the following struct is declared for the permission list of a file in Linux. Each permission (u or g or o) is represented as an octal. For example, u=7 means rwx, u=5 means r-x. Note: "unsigned char" means a byte, not a character or a letter or a string. typedef struct { unsigned int uid; // owner id unsigned int gid; // group id unsigned char u; // owner's permission unsigned char g; // group's permission unsigned char...

  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

  • I need to construct a c++ class that defines a parser. This parser will be able...

    I need to construct a c++ class that defines a parser. This parser will be able to break up a string into tokens. A token is a distinct string of text – it can be a word, a symbol, or a combination of these. Your parser will eliminate whitespace and break string snippets into individual tokens (where single-character tokens are defined at runtime). Your parser should behave as follows: 1) Whitespace (spaces, tabs, and new lines) is used only to...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • Stack help. I need help with my lab assignment. Complete a method for a class named...

    Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...

  • IN C++ Write a program in c++ that will read from a file the following sentence:...

    IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • In C++ please.. I only need the game.cpp. thanks. Game. Create a project titled Lab8_Game. Use...

    In C++ please.. I only need the game.cpp. thanks. Game. Create a project titled Lab8_Game. Use battleship.h, battleship.cpp that mentioned below; add game.cpp that contains main() , invokes the game functions declared in battleship.h and implements the Battleship game as described in the introduction. ——————————————- //battleship.h #pragma once // structure definitions and function prototypes // for the battleship assignment // 3/20/2019 #include #include #ifndef BATTLESHIP_H_ #define BATTLESHIP_H_ // // data structures definitions // const int fleetSize = 6; // number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT