hello there...uhmmm, im having problems with getting the file and storing them...like for example, you ask the user to input a file then that file will be stored...how do you get that file, and where do you store them?? thanks

I think you may have misunderstood the assignment. Are you supposed to ask for the information to be put into the file? The name of the file? or both?

Is this a C or C++ program? What compiler and operating system?

uhmmm ask for the file name then store the file itself...like for example

.....................................................
enter file name of file you would like to store: dragon.jpg
........................................................
dragon.jpg then will be stored
, but idk how to get the file and store it..

yes, it is c++ in linux...help pls...

>>but idk how to get the file and store it

don't know -- you will probably have to ask your teacher. Saving the file is easy but depends on whether you are writing a C or C++ program, which you failed to answer. I can only presume your program already has the data for the find in memory, or its in another file somewhere. But you need to get clarification from the instructions (please post them) or from your teacher.

>>but idk how to get the file and store it

but depends on whether you are writing a C or C++ program, which you failed to answer.

He did answer, he said he's using C++ and using the Linux Operating System.

jaepi, we don't have much information on specifically what your wanting to do and how to get this file.
Are you wanting to type in the file location and copy it to the current directory?.
Are you wanting to copy the file's contents, and write them to a file?

If you are going for the first option.
you can simply run a copy command using system() function to call the linux 'copy' command.

The second option you're looking to use "fstream"
which can be used by including. #include <fstream.h>
in your file.

You need to identify exactly HOW your wanting to get the file,
and HOW your going to store it.

If you have the methods we can give you the code for these methods.


Drag...

>which can be used by including. #include <fstream.h>
Please don't encourage the use of pre-standard headers. We're getting to the point where compilers will refuse to build code that uses them.

Theres absolutley nothing wrong with using the fstream library for handling Input/Output streaming.

Member Avatar for iamthwee

Theres absolutley nothing wrong with using the fstream library for handling Input/Output streaming.

Are you talking about fstream or fstream.h?

using .h is bad

>Theres absolutley nothing wrong with using the fstream library for
>handling Input/Output streaming.
No, there's not. However, when you say to use fstream.h instead of fstream, you're not using the fstream library. You're using some non-standard library with inconsistent semantics that happens to be called fstream.

commented: yes and since he himself pointed out the OP wanted to use c++ there is no excuse for the confusion. +9

naure i love your animated avatar

Member Avatar for iamthwee

How do you get an animated avatar?

commented: Don't be hypocritical -- keep it on topic or don't neg rep for no reason. -2

be a sponsor

>be a sponsor
Or a moderator. One costs you money, the other costs you sanity.

Member Avatar for iamthwee

I think I can live without it then. :D I'm trying to ween myself off the pc.

Member Avatar for iamthwee

Are you back at work narue?

commented: Chat room? +0

Okay, well i'm referring to the fstream library. not the .h file, i was unaware there was a difference.

>i was unaware there was a difference.
Now you are. To use the fstream library, you include <fstream>, not <fstream.h>.

Yes that's pretty obvious.

>>but idk how to get the file and store it

don't know -- you will probably have to ask your teacher. Saving the file is easy but depends on whether you are writing a C or C++ program, which you failed to answer. I can only presume your program already has the data for the find in memory, or its in another file somewhere. But you need to get clarification from the instructions (please post them) or from your teacher.

im using c++ and linux...uhmmm...the user will be asked to input files by entering the file name...the files entered, if valid file, will be then stored into 1 directory...all the files inside this directory will then be compressed to an iso image file using mkisofs in linux...

He did answer, he said he's using C++ and using the Linux Operating System.

jaepi, we don't have much information on specifically what your wanting to do and how to get this file.
Are you wanting to type in the file location and copy it to the current directory?.
Are you wanting to copy the file's contents, and write them to a file?

If you are going for the first option.
you can simply run a copy command using system() function to call the linux 'copy' command.

The second option you're looking to use "fstream"
which can be used by including. #include <fstream.h>
in your file.

You need to identify exactly HOW your wanting to get the file,
and HOW your going to store it.

If you have the methods we can give you the code for these methods.


Drag...

i think, it's near to the first option...i have created a prototype of the program...i used string instead of file, and stored it to an array of strings...

here is my code...

______________________________________________________
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <fstream>

using namespace std;


char x;
char z;
int number_of_files;
string filename;
string store_filename;
string filename_for_iso;
string file_storage[100];

inline void menu(){
        //menu
        cout << "Menu \n";
        cout << "1 - Enter file name to be compressed \n";
        cout << "2 - Exit \n" << "\n";

        cout << "Choose from the menu: ";

        cin >> x;

}

int main(int argc, char *argv[]){

        menu();

        if(x=='1'){
                cout << "How many files would you like to compress?: ";
                cin >> number_of_files;
                cout << "\n";

                for(int i=0; i<number_of_files; i++){
                        cout << "Enter file name ";
                        cout << i+1 << ": ";
                        cin >> filename;

                        if(&filename==0){
                                cout << "Please enter a file: ";
                                cin >> filename;
                        }else{
                                file_storage[i] = filename;
                                cout << "\n";
                        }
                         cout << "Files entered and ready for compression: \n";
                        for(int j=0; j<number_of_files; j++){
                                 cout << file_storage[j] << "\n";
                        }
                }


                //file compression
                cout << "\n" << "Compress files(y/n)?: ";
                cin >> z;
                cout << "\n";

                if(z=='y' || z=='Y'){
                     cout << "Enter file name for compressed ISO file: ";
                     cin >> filename_for_iso;
                     cout << "\n";
                     cout << "compressing....\n";
                     cout << "compression successful, " << filename_for_iso << ".iso is now ready \n";
                }else{
                     cout << "Exiting...\n";
                     menu();
                }



        }else{
                cout << "Exiting...\n";
                exit(EXIT_SUCCESS);
        }
}
____________________________________________________

this is just temporary, for me to figure it out...this is the out put...

******************************************************

Menu
1 - Enter file name to be compressed
2 - Exit

Choose from the menu: 1
How many files would you like to compress?: 3

Enter file name 1: picture.jpg

Files entered and ready for compression:
picture.jpg


Enter file name 2: textfile.txt

Files entered and ready for compression:
picture.jpg
textfile.txt

Enter file name 3: music.mp3

Files entered and ready for compression:
picture.jpg
textfile.txt
music.mp3

Compress files(y/n)?: y

Enter file name for compressed ISO file: compressed

compressing....
compression successful, compressed.iso is now ready
*****************************************************

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.