I decided to make a program that keeps the same formatting of the c++ code but inserts the color tags for this forum.
I got that all to work right, but now I am trying to make it not colorize the keywords that are in between the quotation.
I was running into some trouble so I decided before implementing it with quotes I would try and make it not highlight anything between %. But it is not working right
Here is my code, and here it is also ran through my code formatter so you can not only see the code but the problem (at the start in the commented section with the %)
Code:
#include <iostream>
#include <fstream>
#include <string>
// % double int char bool % char bool
using namespace std;
int main()
{
string item;
bool hold = false;
ifstream in_file;
ofstream out_file;
in_file.open("raw.txt");
if ( in_file.fail() )
{
cout << "Error opening input file";
cin.get();
return 1;
}
out_file.open("formated.txt");
if ( out_file.fail() )
{
cout << "Error opening input file";
cin.get();
return 1;
}
while ( !in_file.eof() )
{
if ( in_file.peek() == '\n')
{
out_file << '\n';
in_file.get();
}
else if ( in_file.peek() == ' ')
{
out_file << " ";
in_file.get();
}
else if ( in_file.peek() == '\t')
{
out_file << '\t';
in_file.get();
}
else
{
in_file >> item;
char temp1 = item[0] ;
int i = item.length();
if (temp1 == '%' || item[i-1] == '%' || item == "%")
{
if (hold == false ) hold = true;
else if (hold == true ) hold = false;
}
if ( item == "int" || item == "double" || item == "char"
|| item == "using" || item == "namespace" || item == "#include"
|| item == "return" || item == "void" || item == "class"
|| item == "delete" || item == "#ifndef" || item == "#define"
|| item == "#endif" || item == "public" || item == "protected"
|| item == "const" || item == "private" || item == "string"
|| item == "bool" || item == "true" || item == "true;" || item == "false" || item == "false;"
|| item == "if" || item == "if(" || item == "else" || item == "do" || item == "while" || item == "while("
|| item == "friend" || item == "operator"
&& hold == false )
{
item.insert(0,""); //Ignore these 2 lines of code
item.insert(item.length(),""); //The board is detecting the insert color string and it is causing trouble
}
out_file << item;
}//End of else
}//End of while
in_file.close();
out_file.close();
system("formated.txt");
return 0;
}