Reading from file and avoiding white space in blank lines - c++

I'm currently working on a project where I'm reading in commands and I need to avoid whitespace on lines that are blank. I've done good up to this point but for some reason I just can't seem to figure out how to make it work. I thought if(opcode == "\t" || opcode == " ")continue; would take care of, but it didn't. If someone could please have a look and help me out that'd be great.
Here's a small sample of the commands I'm reading in. They are in [label] opcode [arg1][,arg2] format.
#Sample Input
LA 1,1
LA 2,2
\t <<<<<<<Here just to show that it's a blank line with only a tab
TOP NOP
Here is my code:
int counter = 0;
int i = 0;
int j = 0;
int p = 0;
while (getline(myFile, line, '\n'))
{
if (line.length() == 0)
{
continue;
}
if (line[0] == '#')
{
continue;
}
// If the first letter isn't a tab or space then it's a label
if (line[0] != '\t' && line[0] != ' ')
{
string delimeters = "\t ";
int current;
int next = -1;
current = next + 1;
next = line.find_first_of( delimeters, current);
label = line.substr( current, next - current );
Symtablelab[i] = label;
Symtablepos[i] = counter;
if(next>0)
{
current = next + 1;
next = line.find_first_of(delimeters, current);
opcode = line.substr(current, next - current);
if (opcode != "WORDS" && opcode != "INT")
{
counter += 3;
}
if (opcode == "INT")
{
counter++;
}
if (next > 0)
{
delimeters = ", \n\t";
current = next + 1;
next = line.find_first_of(delimeters, current);
arg1 = line.substr(current, next-current);
if (opcode == "WORDS")
{
counter += atoi(arg1.c_str());
}
}
if (next > 0)
{
delimeters ="\n";
current = next +1;
next = line.find_first_of(delimeters,current);
arg2 = line.substr(current, next-current);
}
}
i++;
}
// If the first character is a tab or space then there is no label and we just need to get a counter
if (line[0] == '\t' || line[0] == ' ')
{
string delimeters = "\t \n";
int current;
int next = -1;
current = next + 1;
next = line.find_first_of( delimeters, current);
label = line.substr( current, next - current );
if(next>=0)
{
current = next + 1;
next = line.find_first_of(delimeters, current);
opcode = line.substr(current, next - current);
if (opcode != "WORDS" && opcode != "INT")
{
counter += 3;
}
if (opcode == "INT")
{
counter++;
}
if (next > 0)
{
delimeters = ", \n\t";
current = next + 1;
next = line.find_first_of(delimeters, current);
arg1 = line.substr(current, next-current);
if (opcode == "WORDS")
{
counter += atoi(arg1.c_str());
}
}
if (next > 0)
{
delimeters ="\n\t ";
current = next +1;
next = line.find_first_of(delimeters,current);
arg2 = line.substr(current, next-current);
}
}
}
}

Use std::stringstream and read from your line to std::string variables. In this way the blank will be omitted.
[UPDATE]
If you want to remove blank whitespace from the beginning:
s.erase(s.find_last_not_of(" \n\r\t")+1);
[UPDATE2] Or just count words while reading:
Like in this example:
#include <iostream>
#include <sstream>
#include <string>
int main() {
std::string line;
while (std::getline(std::cin, line))
{
std::string lineNoWS = line;
lineNoWS.erase(lineNoWS .find_last_not_of(" \n\r\t")+1);
if (lineNoWS.empty())
std::cout << "EMPTY LINE\n";
std::string word;
unsigned words = 0;
std::istringstream line_is(line);
while(line_is >> word)
{
std::cout << '\'' << word << "'\n";
++words;
}
std::cout << "(" << words << ")ENDLINE\n";
}
}
Just replace std::cin with your ifstream(file).

You should probably try to make the reading of commands more "generic".
Assuming a line to be valid must start with a label and your labels can only contain "letters", instead of checking for '\t', '\n', '\r', '#', (...)
Why don't you just use the function isalpha ?
Then you need to get the arguments, and assuming they are delimited by ',' your best approach is to split the line according to the ',' delimiter.
Some sample code, that gets you the "label" and a vector with the "arguments", I suggest that you also validate the label (ex. check if the label is only consisted with letters, and assuming that you know the "commands" validate the number and type of arguments that you are retrieving for a specific label.
std::ifstream inStream("c:\\data\\dump.txt");
if(!inStream.fail())
{
while(!inStream.eof())
{
std::string strLine;
std::getline(inStream, strLine);
// Label ?
if( isalpha(strLine[0]))
{
int iIndexOf = strLine.find(" ");
if(iIndexOf != string::npos)
{
std::string strLabel = strLine.substr(0, iIndexOf);
// Arguments ?
std::vector<std::string> vArguments;
std::stringstream ss(strLine.substr(iIndexOf, strLine.size() - iIndexOf));
std::string strArgument;
while(std::getline(ss, strArgument, ','))
{
if(strArgument.size()!=0)
vArguments.push_back(strArgument);
}
std::cout << "label: " << strLabel << std::endl << "arguments list: ";
for(size_t i=0; i<vArguments.size(); i++)
std::cout << vArguments[i] << ";";
std::cout << std::endl;
}
else
{
// No Arguments
std::string strLabel = strLine;
std::cout << "label: " << strLabel << std::endl;
}
}
}
inStream.close();
}

Related

C++: Why am I getting an error: "array initializer must be an initializer list or string literal" when I am in fact using a string?

So here is my question. I am tring to run a program I found online and it is failing to compile. Why am I getting an error: "array initializer must be an initializer list or string literal" when I am in fact using a string? I know this code works for others running windows, but not for me on the m1 Mac.
I am trying to initialize a string array using
string f[3] = " ";
#include <iostream>
#include <cstdio>
#include <string.h>
#include <unistd.h>
#include <cstdlib>
using namespace std;
int main()
{
bool cont = true;
char buffer[100] = {};
while (cont)
{
cout << "\n\nEnter a command: ";
cin.get (buffer, 90);
//REMOVE
if (strstr (buffer,"remove") != NULL)
{
char* t = strchr (buffer,' ');
if(t != NULL)
{
if(remove( t+1 ) != 0)
cout << "\n\nError deleting the file.";
else
cout << "\n\nThe file has successfully been deleted.";
}
else
cout << "\n\nInvalid command. Filename not entered.";
}
//EXIT
else if (strstr (buffer,"exit") != NULL)
cont = false;
//RENAME
else if (strstr (buffer,"rename") != NULL)
{
char* t = strchr (buffer,' ');
if (t != NULL)
{
char* oldName = t + 1;
char* newName = strchr (oldName, ' ');
if (newName != NULL)
{
char temp[30] = {};
int i = 0;
for(char* start = oldName; start != newName; start++)
{
temp[i] = *start;
i++;
}
newName++;
if(rename( temp , newName ) != 0)
cout << "\nError renaming the file.";
else
cout << "\nThe file has successfully been renamed.";
}
else
cout << "\n\nNew Name of the file not entered.";
}
else
cout << "\n\nInvalid command.";
}
//RMDIR
else if (strstr (buffer,"rmdir") != NULL)
{
char* t = strchr (buffer,' ');
if(t != NULL)
{
if(rmdir( t+1 ) != 0)
cout << "\n\nError deleting the directory.";
else
cout << "\n\nThe directory has successfully been removed.";
}
else
cout << "\n\nInvalid command. DirectoryName not entered.";
}
//ECHO
else if (strstr (buffer,"echo") != NULL)
{
char* t = strchr (buffer,'"');
if (t != NULL)
{
char* data = t + 1;
//Extracting the data
char temp[200] = {};
int i = 0;
for(; data[i] != '"'; i++)
{
temp[i] = data[i];
}
//Checking if filename is given or not
char* fileN = strchr (data + i, ' ') ;
if (fileN != NULL)
{
fileN++;
// create a FILE typed pointer
FILE *file_pointer;
// open the file for writing
file_pointer = fopen (fileN, "w");
if (file_pointer != NULL)
{
// Write to the file
fprintf (file_pointer,"%s", temp);
// Close the file
fclose (file_pointer);
cout << "\n\nThe file has been successfully created.";
}
else
cout << "\n\nCould not create the file.";
}
//If filename isn't given then simply print the data on console
else
{
cout << endl << endl << temp;
}
}
else
cout << "\n\nInvalid command. Data not given";
}
//UNZIP
else if (strstr (buffer,"unzip") != NULL)
{
char* t = strchr (buffer,' ');
if(t != NULL)
{
char temp[50] = "tar xvf";
if( system( strcat(temp,t) ) != 0 )
cout << "\n\nError unzipping the file.";
else
cout << "\n\nThe file has been successfully unzipped.";
}
else
cout << "\n\nInvalid command. FileName not entered.";
}
//ZIP
else if (strstr (buffer,"zip") != NULL)
{
char* t = strchr (buffer,' ');
if(t != NULL)
{
char temp[50] = "tar cvf";
if( system( strcat( temp,t) ) != 0 )
cout << "\n\nError zipping the file.";
else
cout << "\n\nThe file has been successfully zipped.";
}
else
cout << "\n\nInvalid command.";
}
else if (strstr (buffer,"out") != NULL)
{
int i = 1;
//Checking '-l'
bool lineByLine = false;
char* lpos = strstr (buffer,"-l");
if (lpos != NULL)
{
lineByLine = true;
i++;
}
string s(buffer);
string fileN = "";
string delimiter = " ";
size_t pos = 0;
while ( i > 0 )
{
pos = s.find(delimiter);
s.erase(0, pos + delimiter.length());
i--;
}
//Now extracting the file names
string f[3] = " ";
i = 0;
while ( (pos = s.find(delimiter)) != -1)
{
f[i] = s.substr(0, pos);
s.erase(0, pos + delimiter.length());
i++;
}
//if atleast one filename is present
if ( s != "out" && s != "-l" && s != "" )
{
f[i] = s;
//Opening the files and printing the contents
int c;
FILE *file;
int j = 0;
bool delay = false;
char x;
while ( j <= i)
{
char fName[50];
strcpy(fName, f[j].c_str());
//Printing the contents of the file(s)
file = fopen(fName, "r");
char line[256];
cout << "\n\nThe contents of the file " << fName << " are as follows : \n\n";
if (file)
{
if (lineByLine)
{
while (fgets(line, sizeof(line), file))
{
printf("%s", line);
//Delay loop
delay = true;
while(delay)
{
cout << "\n\nPress some key to print the next line\n\n";
getchar();
delay = false;
}
}
}
else
{
while ((c = getc(file)) != EOF)
putchar(c);
}
fclose(file);
}
else
cout << "\n\nCould not open the file " << fName << " .";
j++;
//Delay loop
delay = true;
while(delay)
{
cout << "\n\nPress some key to continue\n\n";
getchar();
delay = false;
}
}
}
else
cout << "\n\nNo filename entered.\n\n";
}
else
cout << "\n\nInvalid Command. Kindly enter a valid command.";
cin.ignore();
}
cout << "\n\n\nExiting the CLI.\n\n";
return 0;
}
If you are trying to create a string of length 3, you should do this:
string f(3, ' ');
If you are trying to create an array of 3 different strings, then the issue with your code is that you have a type mismatch - you are trying to assign a single string to an array of strings. Instead, you would want to do this:
string f[3] = {" ", " ", " "};
Looking at your code, it looks like you want to create an array of strings. However, it also looks like you could be reading in any number of strings (unless there is some logic in your code where you are confident it will always be 3?) so I recommend using a std::vector.
std::vector<std::string> f;
Which you can add strings to with the push_back() method like this:
f.push_back(s.substr(0, pos));

Trying to find the number of words without counting the spaces

I am trying to find the number of words in from the input by user but i am asked not to find it through counting the spaces since the user can input a single letter and a bunch of spaces and it will count it as number of words
I have tried it with counting the number of spaces but i can not think of another way to count the number of words
char Array[100];
{
//variable declaration
int words = 0;
// input
cout << "Enter string: ";
cin.getline(Array, 100);
// Number of words
for (int i = 0; i < strlen(Array); i++)
{
if (Array[i] == ' ')
words++;
}
cout << "Number of words in the string are: " << words + 1;
cout << endl;
}
I want to find the number of words with another method rather than counting it through the number of spaces.Any help is appreciated.I am a beginner so could you not use something complicated to solve the problem like a getloc.
You just have to count the number of times the space character is followed immediately by a non-space character.
int firstNonSpace = 0;
while (Array[firstNonSpace] == ' ') //to skip spaces at the beginning of input
{
firstNonSpace++;
}
for (int i = firstNonSpace; i < strlen(Array) - 1; i++)
{
if (Array[i] == ' ' && Array[i+1] != ' ')
words++;
}
if(words || firstNonSpace == 0)
words++; //do not increment if the input is empty or only spaces.
cout << "Number of words in the string are: " << words;
See Live Demo
Note that you will have to handle the case when the input exceeds the bounds of the array so as not to run into undefined behavior.
The easiest way is to let the standard library parse the words for you, eg:
#include <iostream>
#include <string>
#include <sstream>
int main () {
//variable declarations
std::string line, word;
int words = 0;
// input
std::cout << "Enter string: ";
std::getline(std::cin, line);
// Number of words
std::istringstream iss(line);
while (iss >> word) {
++words;
}
std::cout << "Number of words in the string are: " << words << std::endl;
return 0;
}
If you don't want to use std::string (ie, to avoid memory allocations), you could do this instead:
#include <iostream>
#include <algorithm>
#include <cctype>
int main() {
//variable declarations
char Array[100];
int words = 0;
// input
std::cout << "Enter string: ";
std::cin.getline(Array, 100);
// Number of words
char *ptr = Array;
char *end = ptr + std::cin.gcount();
while (ptr != end) {
ptr = std::find_if(ptr, end, [](char c){ return !std::isspace(static_cast<unsigned char>(c)); });
if (ptr == end) break;
ptr = std::find_if(ptr+1, end, [](char c){ return std::isspace(static_cast<unsigned char>(c)); });
++words;
}
std::cout << "Number of words in the string are: " << words << std::endl;
return 0;
}
Or, if you want to completely avoid standard library algorithms:
#include <iostream>
int main() {
//variable declarations
char Array[100];
int words = 0;
// input
std::cout << "Enter string: ";
std::cin.getline(Array, 100);
// Number of words
char *ptr = Array;
char *end = ptr + std::cin.gcount();
while (ptr != end) {
while ((*ptr <= ' ')) && (ptr != end)) ++ptr;
if (ptr == end) break;
++ptr;
while ((ptr != end) && (*ptr > ' ')) ++ptr;
++words;
}
std::cout << "Number of words in the string are: " << words << std::endl;
return 0;
}
You could then wrap the parsing into a helper function to clean up the counting loop:
#include <iostream>
//#include <algorithm>
//#include <cctype>
bool findNextWord(char* &begin, char *end) {
/*
begin = std::find_if(begin, end, [](char c){ return !std::isspace(static_cast<unsigned char>(c)); });
if (begin == end) return false;
begin = std::find_if(begin+1, end, [](char c){ return std::isspace(static_cast<unsigned char>(c)); });
return true;
*/
while ((begin != end) && (*begin <= ' ')) ++begin;
if (begin == end) return false;
++begin;
while ((begin != end) && (*begin > ' ')) ++begin;
return true;
}
int main() {
//variable declarations
char Array[100];
int words = 0;
// input
std::cout << "Enter string: ";
std::cin.getline(Array, 100);
// Number of words
char *ptr = Array;
char *end = ptr + std::cin.gcount();
while (findNextWord(ptr, end)) {
++words;
}
std::cout << "Number of words in the string are: " << words << std::endl;
return 0;
}
Just do the following change and bob's your uncle :)
if(array[i] == ' ') {
continue;
}
words++;
while(array[i] != ' ') {
i++;
}
I was looking online and found them all very confusing this is simple and works
string state;//variable for statement the user may enter
int i; //variable for the for loop
int wordtally; // variable for word count
//this checks if its a space or not and then if it is a space it loops untill it
//reaches a character then after reaching a character loops until it hits a space anmd
//when that happens the counter goes up making it so every time a blank amount of spaces
//then a word it increases word count
for ( i=0 ; i < state.length() ; i++ )
{
if(state[i]==' '){
do {
i++;
}while(state[i]==' ');
}
else if(state[i]>=' '){
do {
i++;
}
while(state[i]>' ');
wordtally++ ;
}
}

How to get multiple input with char and multiple output with int? C++

I'm quite new to C++, so I apologize if I am not sounding technical. I am having a little trouble getting a multiple input and output with my code, I'm thinking I should have a loop to get the data but i'm not sure how i'd go about that in my code, I've thought about using getline() but that doesn't seem to want to work with Char.
I've tried getline but I'm not sure how to implement it with the Char input, I believe I may need a separate loop as well but again not too sure. I'm thinking it could be done to EoF as well.
Here's my code:
int main()
{
char inpval;
int outval = 0;
cout << "Enter a Roman Number to convert: " << endl;
while (cin.get(inpval))
{
inpval = toupper(inpval);
if (inpval == 'M')
outval = outval + 1000;
else if (inpval == 'D') {
inpval = cin.peek();
inpval = toupper(inpval);
if (inpval == 'M') {
outval = outval - 500;
continue;
} else {
outval = outval + 500;
continue;
}
}
//etc
cout << "The Equivalent Arabic value is:" << endl;
cout << outval << "\n";
return 0;
}
My expected output is:
(All on newline)
Input:
I
II
IV
V
VI
Output:
1
2
4
5
6
Actual output is:
Input:
I
Output:
1
P.S: The program converts Roman Numeral chars to their respected number.
Any help is appreciated!
You can take input multiple items from cin, using below syntax.
cin >> a;
cin >> b;
cin >> c;
Another way is also there
cin >> a >> b >> c;
This technique is called "operator chaining" which is similar to the above.
Do you have any problem doing it like this?
cout << "Enter a Roman Numeral" << endl;
string inpval;
cin >> inpval;
while (inpval != "exit")
{
int outval = 0;
if (inpval == "I")
outval = 1;
else if (inpval == "II")
outval = 2;
else if (inpval == "III")
outval = 3;
else if (inpval == "IV")
outval = 4;
// ect
cout << "The Equivalent Arabic value is: " << outval << endl << endl;
cout << "Enter next numeral: (type exit to exit) " << endl;
cin >> inpval;
}
Method 1: Use getchar(), Calculate/Convert Roman to integer until you encounter a space ' ',when you get a space ' ' output the integer and do the same next roman number until you get another space ' ' or newline '\n' and stop the program once you encounter newline '\n'.
Method 2:Use type std::string and take input with getline. Then iterate through the string and calculate until you find space ' ' output the number, do the same till you find next space ' ' or end when string ends.
If you know # of Roman numbers you want to convert you can put it in a loop.
Hope this helps.
Example(Method 2)
#include <bits/stdc++.h>
int value(char r)
{
if (r == 'I')
return 1;
if (r == 'V')
return 5;
if (r == 'X')
return 10;
if (r == 'L')
return 50;
if (r == 'C')
return 100;
if (r == 'D')
return 500;
if (r == 'M')
return 1000;
return -1;
}
int main()
{
int out=0;
std::string s;
std::string::iterator i; //string iterator
//for more info go to https://www.geeksforgeeks.org/stdstring-class-in-c/
getline(std::cin,s);
for (i = s.begin(); i!= s.end() ; ++i)
{
if(*i != ' ')//Encounter a space, output result and
{ //go to next roman numeral
int s1 = value(*i);
if (*(i+1) != ' ' || *(i+1) != '\0')
{
// Getting value of i+1 nth Element
int s2 = value(*(i+1));
// Comparing both values
if (s1 >= s2)
{
// Value of current symbol is greater
// or equal to the next symbol
out = out + s1;
}
else
{
out = out + s2 - s1;
i++; // Value of current symbol is
// less than the next symbol
}
}
else
{
out = out + s1;
i++;
}
}
else
{
std::cout<<out<<" ";
out = 0;
}
}
std::cout<<out<<" ";
std::cout<<std::endl;
return 0;
}
Input:
I II MM MCMIV
Output:
1 2 2000 1904

Infix to Postfix to Answer Program (thought process right?)

I'm aware that there's already stuff here regarding this but I'm just posting to check if my logic lines up with my code (if I'm thinking about this whole infix Postfix thing the way I should be).
The code I've seen regarding this topic on this site look a little different from mine. I'm kind of a novice at C++. Anyway, my code so far looks like it is just fine and should work just fine but it's not working the way it should. I've included my thought process as comments in the code below. Please let me know if what I'm thinking is okay.
Here's the code:
#include <iostream>
#include <stack>
#include <sstream>
#include <string>
using namespace std;
int priority (string item)
{
int prior = 0;
if (item == "(")
{
prior = 1;
}
if ((item == "+") || (item == "-"))
{
prior = 2;
}
else if ((item == "*") || (item == "/"))
{
prior = 3;
}
else
{
prior = 4;
}
return prior;
}
int main()
{
stack<string> st;
string output;
cout << "Welcome. This program will calculate any arithmetic expression you enter" << endl;
cout << "Please enter an arithmetic expression below: " << endl;
char line[256];
cin.getline(line, 256);
string exp;
exp = line;
cout << "This is the expression you entered: ";
cout << exp << endl;
string item;
istringstream iss(exp);
iss >> item;
// While there are still items in the expression...
while ( iss )
{
// If the item is a number
if (isdigit('item') == true)
{
output = output + " " + item;
}
// If the stack is empty
else if (st.size() == 0)
{
st.push(item);
}
// If the item is not a number
else if (isdigit('item') == false)
{
// convert that item in the expression to a string
atoi(item.c_str());
int prior1 = 0;
int prior2 = 0;
// If that string is a LEFT PARENTHESIS
if (item == "(")
{
st.push(item);
}
// If that string is a RIGHT PARENTHESIS
else if (item == ")")
{
while ((st.empty() == false) && (st.top() != "("))
{
output = st.top() + " ";
st.pop();
}
st.pop();
}
else
{
// store what is returned from "priority" in "prior1"
prior1 = priority(item);
// pass item on top of the stack through "priority"
// store that in "prior2;
prior2 = priority(st.top());
// while loop here, while item has a higher priority...
// store numbers in a variable
while (prior1 > prior2)
{
output = output + " " + st.top();
st.pop();
prior2 = priority(st.top());
}
}
}
}
while (st.empty() == false)
{
output = st.top() + " ";
st.pop();
}
cout << "Here's the postfix: " << output << endl;
}
This is for evaluating postfix to an actual answer:
// EVALUATE POSTFIX
stack<int> st2;
string output2;
istringstream iss2(exp);
iss2 >> item;
while (iss)
{
// If the item is a number
if (isdigit('item') == true)
{
st.push(item);
}
if (isdigit('item') == false)
{
// store item in a variable
// pop another item off the stack
// store that in a variable.
// apply operator to both.
// push answer to the top of the stack.
int m = 0;
int n = 0;
int total = 0;
m = st2.top();
st2.pop();
n = st2.top();
st2.pop();
if (item == "+")
{
total = m + n;
st2.push(total);
}
else if (item == "-")
{
total = m - n;
st2.push(total);
// add the thing you popped of the stack with the first thing on the stack
}
else if (item == "*")
{
total = m * n;
st2.push(total);
}
else if (item == "/")
{
total = m / n;
st2.push(total);
}
}
}
cout << "Here's your answer: " << st2.top() << endl;
}
Am I thinking about this whole infix-postfix thing the way I should be? Am I on track to solving this problem? My apologies if this question seems simple. I'm kind of a novice at this. Thank you very much.

C++ Multiple delimiters with more than one char

In c++, I'm having trouble coding multiple delimiters with single char delimiters and string delimiters (e.g. "<=" as a delimiter as opposed to '='). The code below works with single char delimiters (I've set the delimiters as space, comma, dot, plus and equal) and separates the words in string line nicely. However, I don't know how to add string delimiters to this code.
std::string delimiters = " ,.+=";//I want "<=" added as a single delimiter
std::string line = "this+is,a.string=testing one";
std::size_t prev = 0, pos;
while ((pos = line.find_first_of(delimiters, prev)) != std::string::npos)
{
if (pos > prev)
{
cout << line.substr(prev, pos-prev) << endl;
prev = pos + 1;
}
}
if (prev < line.length()){
cout << line.substr(prev, std::string::npos) << endl;
}
Here is one way you could do it by erasing the delimiters you find from the line_copy string, having a special if statement for the special delimiter. Full example here:
auto pos = find_first_of(begin(line_copy), end(line_copy), begin(delimiters),
end(delimiters));
while (pos != line_copy.end()) {
if (pos != line_copy.end()) {
if (*pos == '<' && *(pos + 1) == '=') {
cout << "delimiter: \'";
cout << string(pos, pos + 2) << "\'" << endl;
// remove the delimiters from copy string
line_copy.erase(pos, pos + 2);
}
else {
cout << "delimiter: \'" << *pos << "\'" << endl;
// remove the delimiters from copy string
line_copy.erase(pos, pos + 1);
}
}
cout << endl;
pos = find_first_of(begin(line_copy), end(line_copy), begin(delimiters),
end(delimiters));
}
I would change the line
rev = pos + 1
in the following way:
if (pos > prev)
{
cout << line.substr(prev, pos-prev) << endl;
prev = line.find_first_not_of(delimiters, pos))
}
So once you hit a delimiter then you move to the fiurst char not being a delimiter.
Do a two character search one by one.
Search for "<" first and if found search for an immediate "=" if found, do substr otherwise continue searching.