Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:19:14+00:00 2026-06-01T20:19:14+00:00

I have a text file with two columns and unknown number of lines. So

  • 0

I have a text file with two columns and unknown number of lines. So I want to load two columns into a dynamic two dimensional vector. Here is what I have so far, it is not working. If this was one dimensional, I know how to do this. White space separates two columns. Since i am reading 2 columns, I only need 2 vectors of size n.

vector<vector<string> > component;
ifstream in_file("/tmp/FW.txt", ios::binary);

//Check if the file is open
if(!in_file.is_open()) 
{
   cout << "File not opened..." << endl;
   exit (1);
}

for(int i=0; !in_file.eof(); i++)
{
   in_file >> component.push_back();  
   //component.push_back(in_file);
}

Can someone please tell me how to get this to work? Also If you can tell me how to print the two dimensional vector back, so it looks like original file, that would be nice too. This need to run on Linux(Red hat)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:19:14+00:00Added an answer on June 1, 2026 at 8:19 pm

    How about:

    vector< vector<string> > component;
    ifstream in_file("/tmp/FW.txt"); // N.B., not ios::binary since you're reading text strings
    vector<string> vs( 2 );
    // Assume they are separated by just whitespace
    while( in_file >> vs[0] >> vs[1] )
    {
        component.push_back( vs );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two columns in a text file. I read them into Python into
I have a text file containing two or more types of lines. I would
I have to filter a text file filter.tmp containing two types of lines, this
I have two 3GB text files, each file has around 80 million lines. And
i have two text files file 1 number,name,account id,vv,sfee,dac acc,TDID 7000,john,2,0,0,1,6 7001,elen,2,0,0,1,7 7002,sami,2,0,0,1,6 7003,mike,1,0,0,2,1
I have two text file. file1.txt has: gedit google chrome git vim foo bar
I have text file with some stuff that i would like to put into
I have a form with two text boxes, in one I want to show
Here’s the scenario. I have a text file(alpha), single column, with a bunch of
I have a postgres function that returns two columns result, data (int), (text) If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.