How to make a vector permanent to the memory | SoloLearn: Learn to code for FREE!

+8

How to make a vector permanent to the memory

I wany to have an input and push it to the vector then run the programe and after closing the programe how I could output the same thing which I inputed previously? I was wondering to make the vector static with static keyword but it doesn't workded...... Please help....and one thing.... I think this question needs no code cause even I am so confused that how I could make such programe

8/8/2020 1:02:04 PM

Gorom_Pani

11 Answers

New Answer

+4

Just add all the inputs in a file (maybe txt) I don't know C and C++ so I can't show you a code related to that But I know python! I can show you an example! Do you want?

+4

codemonkey I wanna make this happend in SoloLearn But is it possible in SoloLearn....And also How nova have done those things.....please explain

+4

codemonkey Can you tell me how I could do that with files and plz give me the code to understand clearly

+4

AteFish https://www.tutorialspoint.com/read-file-line-by-line-using-cplusplus

+3

codemonkey I wanted to create a namelist....... I wanted to add every name in a vector and keep it on the memory permanently......and everytime the viewer enter a name I could push the name in the vector and make it parmanent in memory

+3

There is no way to save data to memory when the program exits. Once the program exits, the data will be lost. You will need to save the data to a file before the program closes. Then when you open the program you can import the data again

+2

codemonkey I have read this but how I could detect every name in the file?

+1

codemonkey How I am gonna read each line.....besides in C++ tutorial there is no function which can do that

+1

AteFish, file handling was covered in the C++ Tutorial, which you have completed. See: http://www.cplusplus.com/reference/iolibrary/ (C++) http://www.cplusplus.com/reference/cstdio/ (C/C++)

+1

Basic example with some useful links: https://code.sololearn.com/cxkl7hITXLFj/# Take a look at https://github.com/goblinhack/c-plus-plus-serializer, a header only serializer Otherwise use a database, e.g. http://srombauts.github.io/SQLiteCpp/

0

codemonkey Please scroll up and see What I wanted to do and I also use codeblocks