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 6962203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:37:45+00:00 2026-05-27T15:37:45+00:00

It seems pretty dumb, but I am having a hard time loading a matrix

  • 0

It seems pretty dumb, but I am having a hard time loading a matrix type double I have on a txt file. inside it has signed doubles things like

11707.2 -919.303 -322.04 2260.71 2443.85 -4629.31 3082.64 -4209.86
-1741.71 298.192 -5658.34 2377.03 -3039 -2049.99 2788 -1915.9 

and so on, and I have it in a txt file.

I have used fscanf, ifstream and all sorts of things I have found and am familiar with, but I have not been able to load it. I found on related question but the procedure didnt help me.

I need to save those values to a float array, but right now I just want to be able to load them correctly, all values look like the ones I wrote.

help please? any one?

Related question: Reading a .txt text file in C containing float, separated by space

  • 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-05-27T15:37:46+00:00Added an answer on May 27, 2026 at 3:37 pm

    Standard idiom:

    #include <fstream>   // for std::ifstream
    #include <sstream>   // for std::istringstream
    #include <string>    // for std::string and std::getline
    
    int main()
    {
        std::ifstream infile("thefile.txt");
        std::string line;
    
        while (std::getline(infile, line))
        {
            // process line, e.g. one matrix per line:
    
            std::istringstream iss(line);
            std::vector<double> m;
            m.reserve(16);
            double d;
    
            if (iss >> d) { m.push_back(d); }
            else { /* error processing this line */ }
    
            if (m.size() != 16) { /* error */ }
    
            // use m
        }
    }
    

    If your matrix data is spread out over multiple lines, modify the code accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a pretty softball question, but I always have a hard time
So this seems pretty basic but I can't get it to work. I have
Seems pretty simple but I can't get it to work. I have two divs
The question seems pretty well formulated I have a virtual machine which implements only
I need a command to replace the hosts file on my machine. Seems pretty
It seems pretty common to me to have an argument, in a dynamically typed
This seems pretty simple and maybe I'm just overlooking the proper flag , but
OK - I feel pretty dumb asking such a basic question, but hey. I'm
the question title seems pretty confusing, but this is what i want to achieve.
This seems pretty straight forward but I'm not sure what is going wrong. I'm

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.