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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:29:17+00:00 2026-06-15T15:29:17+00:00

I’ve read through a few threads detailing how to tokenize strings, but I’m apparently

  • 0

I’ve read through a few threads detailing how to tokenize strings, but I’m apparently too thick to adapt their suggestions and solutions into my program. What I’m attempting to do is tokenize each line from a large (5k+) line file into two strings. Here’s a sample of the lines:

               0      -0.11639404 
   9.0702948e-05    0.00012207031 
    0.0001814059      0.051849365 
   0.00027210884      0.062103271 
   0.00036281179      0.034423828 
   0.00045351474      0.035125732 

The difference I’m finding between my lines and the other sample input from other threads is that I have a variable amount of whitespace between the parts that I want to tokenize. Anyways, here’s my attempt at tokenizing:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    ifstream input;
    ofstream output;
    string temp2;
    string temp3;

    input.open(argv[1]);
    output.open(argv[2]);
    if (input.is_open())
    {
        while (!input.eof())
            {   
                getline(input, temp2, ' ');
                while (!isspace(temp2[0])) getline(input, temp2, ' ');
                getline (input, temp3, '\n');               
            }
            input.close();
            cout << temp2 << endl;
            cout << temp3 << endl;
    return 0;
}

I’ve clipped it some, since the troublesome bits are here. The issue that I’m having is that temp2 never seems to catch a value. Ideally, it should get populated with the first column of numbers, but it doesn’t. Instead, it is blank, and temp3 is populated with the entire line. Unfortunately, in my course we haven’t learned about vectors, so I’m not quite sure how to implement them in the other solutions for this I’ve seen, and I’d like to not just copy-paste code for assignments to get things work without actually understanding it. So, what’s the extremely obvious/already been answered/simple solution I’m missing? I’d like to stick to standard libraries that g++ uses if at all possible.

  • 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-15T15:29:17+00:00Added an answer on June 15, 2026 at 3:29 pm

    Under the circumstances, you can simply ignore the whitespace. Extract strings, and the extractor will automatically skip leading white-space, and read a string of non white-space characters:

    int main(int argc, char **argv) { 
        std::ifstream in(argv[1]);
        std::ofstream out(argv[2]);
    
        std::string temp1, temp2;
    
        while (in >> temp1 >> temp2)
            ;
        std::cout << temp1 << "\n" << temp2;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but

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.