Ok I'm going to try to be as specific as possible. Here's my input file (at least to some effect):

#'s searched
1    3    3100    56801   .52   87925.32   2   Mitchell 1
                                                               boudreax 2
1    4    5480    56825   .81   68939.09   0
1    5    8520    56829   .89   10892.40   3   guillott 3
                                                                    harper   1
                                                                    galvez   3

The number I have indicated is the number of times that particular item has been searched. so basically what I need to do is save all those names and that last integer in two members of a structure. The only problem is when I read in the compiler will ignore leading white spaces. so it'll go to the second line and read the first item (Boudreaux) into the same member as the first item in the line above when really it should be with the rest of the names.

I surely hope my inquiry makes sense

Dani AI

Generated

— the core problem is that formatted extraction with operator>> collapses whitespace and ignores line breaks, so a name that sits on an indented continuation line will be treated as the next token of the previous record. The reliable fix is to read the file line‑by‑line (std::getline), decide whether a line starts a new record, and parse the remainder of that line plus any following continuation lines into name/count pairs.

Suggested approach, in short:

  • Read each input line with std::getline.
  • Skip blank/comment lines.
  • If the first non‑space character indicates a new record (for your file that’s a digit for the ID), start a new struct and use std::istringstream to pull off the first seven tokens.
  • For the remainder of that line — and for any subsequent indented/continuation lines — parse tokens so that numeric tokens are treated as counts and the preceding token(s) form the name. That lets names contain spaces because you collect non‑numeric tokens until you see the integer that follows the name.
  • Push the finished record when a new record begins or at EOF.

A compact parsing helper (core idea):

#include <sstream>
#include <string>
#include <vector>
#include <cctype>

struct NameCount { std::string name; int count; };

bool isInteger(const std::string &s) {
  if(s.empty()) return false;
  size_t i = (s[0] == '+' || s[0] == '-') ? 1 : 0;
  for(; i < s.size(); ++i) if(!std::isdigit((unsigned char)s[i])) return false;
  return true;
}

void parseTail(std::istringstream &iss, std::vector<NameCount> &out) {
  std::string tok, nameAccum;
  while(iss >> tok) {
    if(isInteger(tok)) { out.push_back({nameAccum, std::stoi(tok)}); nameAccum.clear(); }
    else { if(!nameAccum.empty()) nameAccum.push_back(' '); nameAccum += tok; }
  }
}

Troubleshooting: if some “new” lines aren’t numeric, change the new‑record test (inspect the first token rather than just the first char). Log malformed lines and check for stray whitespace. This line‑oriented method preserves continuation structure and will keep the name/count pairs attached to the correct record.

ok my file didn't line up right but I hope you can tell what I'm asking regardless

ok yeah I posted this prematurely. I just had an epiphany and I figured it out. Disregard

I've reconsidered and the idea I had does not work.
basically I have to save the first 7 peices of info into an array of structues and then the last two into an array of structures within that structure. I don't know how to get the right peices of info into the right members.

come on. Someone has to know this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.