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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:43:29+00:00 2026-06-12T12:43:29+00:00

I have a file which contains pixel coordinates in the following format : 234

  • 0

I have a file which contains pixel coordinates in the following format :

234 324
126 345
264 345

I don’t know how many pairs of coordinates I have in my file.

How can I read them into a vector<Point> file? I am a beginner at using reading functions in C++.

I have tried this but it doesn’t seem to work :

vector<Point> iP, iiP;

ifstream pFile, rFile;
pFile.open("D:\\MATLAB\\WORKSPACE_MATLAB\\pData.txt");
rFile.open("D:\\MATLAB\\WORKSPACE_MATLAB\\rData.txt");

string rBuffer, pBuffer;
Point rPoint, pPoint;

while (getline(pFile, pBuffer))
{
    getline(rFile, rBuffer);

    sscanf(rBuffer.c_str(), "%d %d", rPoint.x, rPoint.y);
    sscanf(pBuffer.c_str(), "%d %d", pPoint.x, pPoint.y);

    iP.push_back(pPoint);
    iiP.push_back(rPoint);
}

I receive some odd memory errors. Am I doing something wrong? How can I fix my code so that it can run?

  • 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-12T12:43:31+00:00Added an answer on June 12, 2026 at 12:43 pm

    Thanks to Chris Jester-Young and enobayram I have managed to solve my problem. I have added bellow my code.

    vector<Point> iP, iiP;
    
    ifstream pFile, rFile;
    pFile.open("D:\\MATLAB\\WORKSPACE_MATLAB\\pData.txt");
    rFile.open("D:\\MATLAB\\WORKSPACE_MATLAB\\rData.txt");
    stringstream ss (stringstream::in | stringstream::out);
    
    string rBuffer, pBuffer;
    
    
    while (getline(pFile, pBuffer))
    {
        getline(rFile, rBuffer);
    
        Point bufferRPoint, bufferPPoint;
    
        ss << pBuffer;
        ss >> bufferPPoint.x >> bufferPPoint.y;
    
        ss << rBuffer;
        ss >> bufferRPoint.x >> bufferRPoint.y;
    
        //sscanf(rBuffer.c_str(), "%i %i", bufferRPoint.x, bufferRPoint.y);
        //sscanf(pBuffer.c_str(), "%i %i", bufferPPoint.x, bufferPPoint.y);
    
        iP.push_back(bufferPPoint);
        iiP.push_back(bufferRPoint);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file which contains data in the following format: filename.jpg,132,234,234,345,4555,23333,344,...,333 I have
I have a file which contains lines of data in the following format: a11
I have a txt file which contains data in the following format: X1 Y1
I have a file which contains lines of the following format: w1#1#x w2#4#b w3#2#d
I have file which contains the following data: -------------------[ server10 ]------------------- user1 user2 user99
I have an HTML file which contains the following line: <div><img src=img1.gif><br>My Text</div> I'm
I have a zip file which contains the following directory structure: dir1\dir2\dir3a dir1\dir2\dir3b I'm
I have a file which contains multiple lines of this format: Item A 62.7
i have a file which contains a lot of update query and some other
I am using Ruby (1.9.3) and Rails (3.2.2). I have tasks file which contains

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.