Finding information in parts of txt document and storing them in variablesifstream opens files named by cin but not when pulled from an array. Any difference between cin and a regular string definition?**Compiler error** - getline() function not accepting first parameter “std:ifstream” what is my issue?mixing cin and getline input issuesgetline does not take any inputgetline(cin, str) not workingHow to fix string user input without using cin.ignore() and clear()— C++?Why won't my cout statements print after opening a textfile?I'm having trouble dynamically allocating my structIterating values into a vector while reading in a file using getlineWhy is getline (from a file) to cout (that line) not printing the line?

Query about absorption line spectra

Is it possible to use .desktop files to open local pdf files on specific pages with a browser?

MAXDOP Settings for SQL Server 2014

Does having a TSA Pre-Check member in your flight reservation increase the chances that everyone gets Pre-Check?

Did US corporations pay demonstrators in the German demonstrations against article 13?

ArcGIS not connecting to PostgreSQL db with all upper-case name

Why has "pence" been used in this sentence, not "pences"?

Do Legal Documents Require Signing In Standard Pen Colors?

Is XSS in canonical link possible?

Freedom of speech and where it applies

Flux received by a negative charge

Varistor? Purpose and principle

Why did the HMS Bounty go back to a time when whales are already rare?

Open a doc from terminal, but not by its name

Visiting the UK as unmarried couple

Greco-Roman egalitarianism

Are lightweight LN wallets vulnerable to transaction withholding?

Translation of Scottish 16th century church stained glass

How do I extrude a face to a single vertex

What linear sensor for a keyboard?

Create all possible words using a set or letters

Why did the EU agree to delay the Brexit deadline?

Can somebody explain Brexit in a few child-proof sentences?

Is it possible to have a strip of cold climate in the middle of a planet?



Finding information in parts of txt document and storing them in variables


ifstream opens files named by cin but not when pulled from an array. Any difference between cin and a regular string definition?**Compiler error** - getline() function not accepting first parameter “std:ifstream” what is my issue?mixing cin and getline input issuesgetline does not take any inputgetline(cin, str) not workingHow to fix string user input without using cin.ignore() and clear()— C++?Why won't my cout statements print after opening a textfile?I'm having trouble dynamically allocating my structIterating values into a vector while reading in a file using getlineWhy is getline (from a file) to cout (that line) not printing the line?













1















I have a large .txt document holding information. It is structured in this kind of format:




ID: 54670
Gender: M
Name: John Doe
Address: Blah Blah Blah
Email: JohnDoe@.com


I'm trying to create a program that allows one to enter the ID. The program will find the ID in the text document and then store the ID,Gender,Name,Address, etc.. in variables.
I can search for the ID and print following lines. But I'm lost on how to store particular parts of each line and only storing the info from say 5 lines after finding the ID. This is all i have so far. Any pointers would be much appreciated. I have just started teaching myself to code in the last couple weeks. So you are all such a great resource.



struct userInfo

int id;
char gender;
std::string name,address,email;
;
std::string search,line;
std::ifstream inFile;
inFile.open("iData.txt");

if (!inFile)

std::cout << "Was unable to open file!";
return 1;


std::cout << "Enter I.D" << std::endl;
std::getline(std::cin, search);

while (inFile.good())

std::getline(inFile, line);
if (line.find(search) != std::string::npos)

std::cout << line << std::endl;


inFile.close();









share|improve this question




























    1















    I have a large .txt document holding information. It is structured in this kind of format:




    ID: 54670
    Gender: M
    Name: John Doe
    Address: Blah Blah Blah
    Email: JohnDoe@.com


    I'm trying to create a program that allows one to enter the ID. The program will find the ID in the text document and then store the ID,Gender,Name,Address, etc.. in variables.
    I can search for the ID and print following lines. But I'm lost on how to store particular parts of each line and only storing the info from say 5 lines after finding the ID. This is all i have so far. Any pointers would be much appreciated. I have just started teaching myself to code in the last couple weeks. So you are all such a great resource.



    struct userInfo

    int id;
    char gender;
    std::string name,address,email;
    ;
    std::string search,line;
    std::ifstream inFile;
    inFile.open("iData.txt");

    if (!inFile)

    std::cout << "Was unable to open file!";
    return 1;


    std::cout << "Enter I.D" << std::endl;
    std::getline(std::cin, search);

    while (inFile.good())

    std::getline(inFile, line);
    if (line.find(search) != std::string::npos)

    std::cout << line << std::endl;


    inFile.close();









    share|improve this question


























      1












      1








      1








      I have a large .txt document holding information. It is structured in this kind of format:




      ID: 54670
      Gender: M
      Name: John Doe
      Address: Blah Blah Blah
      Email: JohnDoe@.com


      I'm trying to create a program that allows one to enter the ID. The program will find the ID in the text document and then store the ID,Gender,Name,Address, etc.. in variables.
      I can search for the ID and print following lines. But I'm lost on how to store particular parts of each line and only storing the info from say 5 lines after finding the ID. This is all i have so far. Any pointers would be much appreciated. I have just started teaching myself to code in the last couple weeks. So you are all such a great resource.



      struct userInfo

      int id;
      char gender;
      std::string name,address,email;
      ;
      std::string search,line;
      std::ifstream inFile;
      inFile.open("iData.txt");

      if (!inFile)

      std::cout << "Was unable to open file!";
      return 1;


      std::cout << "Enter I.D" << std::endl;
      std::getline(std::cin, search);

      while (inFile.good())

      std::getline(inFile, line);
      if (line.find(search) != std::string::npos)

      std::cout << line << std::endl;


      inFile.close();









      share|improve this question
















      I have a large .txt document holding information. It is structured in this kind of format:




      ID: 54670
      Gender: M
      Name: John Doe
      Address: Blah Blah Blah
      Email: JohnDoe@.com


      I'm trying to create a program that allows one to enter the ID. The program will find the ID in the text document and then store the ID,Gender,Name,Address, etc.. in variables.
      I can search for the ID and print following lines. But I'm lost on how to store particular parts of each line and only storing the info from say 5 lines after finding the ID. This is all i have so far. Any pointers would be much appreciated. I have just started teaching myself to code in the last couple weeks. So you are all such a great resource.



      struct userInfo

      int id;
      char gender;
      std::string name,address,email;
      ;
      std::string search,line;
      std::ifstream inFile;
      inFile.open("iData.txt");

      if (!inFile)

      std::cout << "Was unable to open file!";
      return 1;


      std::cout << "Enter I.D" << std::endl;
      std::getline(std::cin, search);

      while (inFile.good())

      std::getline(inFile, line);
      if (line.find(search) != std::string::npos)

      std::cout << line << std::endl;


      inFile.close();






      c++ variables search ifstream






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 9:13









      Some programmer dude

      303k25265426




      303k25265426










      asked Mar 7 at 9:09









      TheLawmanTheLawman

      122




      122






















          2 Answers
          2






          active

          oldest

          votes


















          1














          you can create



          map<int,list<string>>


          Later parse your file once and split each line and store those value in your map



          //Example code to fetch data from line
          std::getline(inFile, line);
          int pos = line.find(":");
          std::string val = line.substr(pos+1, line.length());


          after that you can just use



          List<string> details = map.find[id];





          share|improve this answer























          • Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

            – TheLawman
            Mar 8 at 4:19


















          0














          you can read the file once and save the info in map so when given id you can get the info map[id].gender






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039914%2ffinding-information-in-parts-of-txt-document-and-storing-them-in-variables%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            you can create



            map<int,list<string>>


            Later parse your file once and split each line and store those value in your map



            //Example code to fetch data from line
            std::getline(inFile, line);
            int pos = line.find(":");
            std::string val = line.substr(pos+1, line.length());


            after that you can just use



            List<string> details = map.find[id];





            share|improve this answer























            • Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

              – TheLawman
              Mar 8 at 4:19















            1














            you can create



            map<int,list<string>>


            Later parse your file once and split each line and store those value in your map



            //Example code to fetch data from line
            std::getline(inFile, line);
            int pos = line.find(":");
            std::string val = line.substr(pos+1, line.length());


            after that you can just use



            List<string> details = map.find[id];





            share|improve this answer























            • Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

              – TheLawman
              Mar 8 at 4:19













            1












            1








            1







            you can create



            map<int,list<string>>


            Later parse your file once and split each line and store those value in your map



            //Example code to fetch data from line
            std::getline(inFile, line);
            int pos = line.find(":");
            std::string val = line.substr(pos+1, line.length());


            after that you can just use



            List<string> details = map.find[id];





            share|improve this answer













            you can create



            map<int,list<string>>


            Later parse your file once and split each line and store those value in your map



            //Example code to fetch data from line
            std::getline(inFile, line);
            int pos = line.find(":");
            std::string val = line.substr(pos+1, line.length());


            after that you can just use



            List<string> details = map.find[id];






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 10:57









            Apoorva RajuApoorva Raju

            1318




            1318












            • Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

              – TheLawman
              Mar 8 at 4:19

















            • Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

              – TheLawman
              Mar 8 at 4:19
















            Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

            – TheLawman
            Mar 8 at 4:19





            Knew i could count on this place. I have a few books but none of them mention maps. I appreciate your help. I have some refinements to do but you have helped me take a big step forward. Much appreciated.

            – TheLawman
            Mar 8 at 4:19













            0














            you can read the file once and save the info in map so when given id you can get the info map[id].gender






            share|improve this answer



























              0














              you can read the file once and save the info in map so when given id you can get the info map[id].gender






              share|improve this answer

























                0












                0








                0







                you can read the file once and save the info in map so when given id you can get the info map[id].gender






                share|improve this answer













                you can read the file once and save the info in map so when given id you can get the info map[id].gender







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 10:34









                user2320641user2320641

                545




                545



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039914%2ffinding-information-in-parts-of-txt-document-and-storing-them-in-variables%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко