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

  • Home
  • SEARCH
  • 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 8457929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:56:24+00:00 2026-06-10T12:56:24+00:00

I have a file that contains lines as below: 25 1 0 0 0

  • 0

I have a file that contains lines as below:

25 1 0 0 0 0
27 1 0 0 0 0
20 0 0 0 0 0
32 1 0 0 0 0
23 1 0 0 0 0
16 0 0 0 0 0
28 1 0 0 0 0

First, I store each line with value=1 in the second column as element of a string array. I call the stored elements back via a for-loop, and parse the contents of the element into integers. How does one do that in c++?

#include <vector> 
#include <iostream>
#include <string>
using namespace std;
   .....
   .....
   .....
   .....
char line[100];
vector<string> vec_line;
string Vline;
int trimVal, compa, nil0, nil1, nil2, nil3;
  ......
  ......
  ......
//then store lines as strings in vec_line as required by the premise above
// after that, retrieve the contents of the elements of the vector
for (int iline=0; iline<vec_line.size(); iline++) {
   cout<<"iline  "<<iline<<"  vec_line[iline]";
   //then I want to parse contents of each string element and store them integer formats
   sscanf(vec_line[iline], "%d %d %d %d %d %d", &trimVal, &compa, &nil0, &nil1, &nil2, &nil3); //how would one do this simple parsing task in c and c++?
}

Thank you.

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

    This is incorrect:

    sscanf(vec_line[iline], "%d %d ...
    

    as the first argument to sscanf() is a const char* and not a std::string. Change to:

    sscanf(vec_line[iline].c_str(), "%d %d ...
    

    Recommend checking the return value of sscanf() to ensure all expected assignments were made:

    if (6 == sscanf(vec_line[iline].c_str(), "%d %d ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that contains around thousands of lines. Format of every line
I have a text file that contains unix style line endings: a 0x0A at
I have a file name foo. That file contains some text (shown below). Can
I have a file that contains information like the below: 1/1/2010 1-2-3-4 1 1/2/2010
I have a file that contain lines that looks like this: >AF001546_1 [88 -
I have a file that might contain a line like this. A B //Seperated
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace
I have a file that contains: foo1 = 1 foo2 = 2 foo3 =
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I

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.