Tygawr -12 Newbie Poster

Hello, I want to learn how to make a syntax highlighter in vc++ 2010. What should I do?

Text,
Window 7,
VC++ 2010

Tygawr -12 Newbie Poster

How can I parse through a large file in a fast and efficient way?

This what I am really doing, I am loading huge files that are about 100MB to 100GB, create a string to store the file contents, and parse through it. Using substr will be slow because substr is creating new strings - if I am correct.

Substr is too slow.

Tygawr -12 Newbie Poster

How can I read a string within a string without using substr?

void ReadStrInStr()
{
    string Str;
    Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    //cout "A-J" in Str
}

I am trying to read all of the files, encode it, and write it. I need to it in a fast and efficient way. Thanks.

Tygawr -12 Newbie Poster

I need to be able to read and write huge files that nearly weighs 20+GB and I need to do it fast. Any suggestions or tips? Thanks.

Oops, made a tiny error.. fixed:
[CODE]
int i = -1;

bool IsPositive()
{
if(i > 0)
return true;
else if(i < 0)
return false;
}

void Example()
{
switch(IsPositive())
{
case true:
cout << "+" << endl;
break;
case false:
cout << "-" << endl;
break;
default:
cout << "Zero/Unknown?" << endl;
break;
}
}
[/CODE]

This isn't rocket science guys...

[CODE]
int i = -1;

bool IsPositive()
{
if(i > 0)
return true;
else if(i < 0)
return false;
}

void Example()
{
switch(IsPositive())
{
case true:
cout << "+" << endl;
break;
case false:
cout << "-" << endl;
break;
case default:
cout << "Zero/Unknown?" << endl;
break;
}
}
[/CODE]

WaltP commented: And yet again you do someone's homework for them. You just don't get it, do you... -4

When I get home, I'll write the code for you.

[CODE]
void IfElseLoopExample()
{
int Month;
cout << "Please enter a numerical value of a month: " << endl;
cin >> Month;

if(Month <= 12)
{
    cout << "A valid month has been entered." << endl;
}
else if(Month > 12 || Month < 0)
{
    cout << "That is not a valid entry. Please enter a new value." << endl;
    cin >> Month;
}

}
[/CODE]

Ancient Dragon commented: Doesn't answer the question -4

Oh, can you please paste what you copied? And if you could, paste your entire code too.

Credits to me, here you go:
[CODE]
int CountUnsoldTicket = 50,
CountSoldAdultTicket = 0,
CountSoldKidTicket = 0,
CountSoldSeniorTicket = 0,
CountSoldFamilyTicket = 0,
CountSoldTicket = 0;

void BuyTicket(string TicketDealerMsg, int &CountPurchasingTicket, int &TicketType)
{
if(CountUnsoldTicket > 0)
{
cout << endl << TicketDealerMsg << endl;
cin >> CountPurchasingTicket;
if(CountPurchasingTicket < 0 || CountPurchasingTicket > CountUnsoldTicket)
{
cout << "Error! Can not be lower than 0 or more than " << CountUnsoldTicket << endl;
system("Pause");
exit(2);
}
else if(CountPurchasingTicket > 0)
{
CountUnsoldTicket -= CountPurchasingTicket;
TicketType += CountPurchasingTicket;
CountSoldTicket += CountPurchasingTicket;
CountPurchasingTicket = 0;
}
cout << endl << "Ticket Dealer: Thanks!" << endl;
cout << endl << "Ticket Dealer: I now have " << CountUnsoldTicket << " ticket(s) left."<< endl;
}
else if(CountUnsoldTicket <= 0)
{
cout << endl << "Sorry, I have no tickets." << endl;
system("Pause");
exit(1);
}
}

void GoToTicketDealer()
{
if(CountUnsoldTicket <= 0)
{
cout << endl << "Ticket Dealer: Sorry, I have no tickets." << endl;
system("Pause");
exit(1);
}
else if(CountUnsoldTicket > 0)
{
if(CountUnsoldTicket == 1)
{
cout << endl << "Ticket Dealer: Hello, would you like to buy my last(1) ticket?" << endl;
}
else if(CountUnsoldTicket > 1)
{
cout << endl << "Ticket Dealer: Hello, would you like to buy some(" << CountUnsoldTicket << ") tickets?" << endl;
}

    char YesNo = 0;
    cout << "(Please enter either 'Y' for yes or 'N' for no)" << endl;
    cin >> YesNo;
    if(YesNo == 'Y' || YesNo == 'y')
    {
        int CountPurchasingTicket = 0; ...
WaltP commented: We do not like cheting here. Please refrain from doing homework for other people. -4

Okay, I will do that then. TY.

I am trying to make a "console book reader". It opens a text file - which contains the story and its current size is nearly 20GB. It creates a substring for the first 500 characters and I can just press any key to read the next 500 character. Its linefeed.

The text file is just a whole story. I am trying to see if its possible for me to be able to read that whole file very fast.

Tygawr -12 Newbie Poster

Hello everyone,
I've attempted to use ifstream to open and read a 20GB file but failed to do so (it takes a very very very long period of time...). So, I need find a fast way to open and read a 20GB .txt file in C++. Thank you!

Hmmm.. okay, I'll re-edit this post once I got the code working! Thanks everyone.

Okay I've finished reading [URL="http://www.fileformat.info/info/unicode/utf8.htm"]this[/URL]. But I still don't quite understand how to read and write a UTF-8 file.

[QUOTE=Ancient Dragon;1780140]>>for(int LineCount = 1; !InputFile.eof(); ++LineCount)

That is the wrong way to read input file because eof() doesn' work like that
[icode]for( line LineCount = 0; getline(InputFile, InputFileLine); ++LineCount)[/icode] The >> operator doesn't accept space in the input, while getline() does. That assumes InputFileLine is of type std::string.[/QUOTE]

Oh, thanks I didn't know that. :0
Fixing!

Tygawr -12 Newbie Poster

OOPS! SORRY WRONG SECTION, I WANTED TO POST IN THE C++ SNIPPETS..

This piece of code will search for a string in a text file and write the results into another file along with the line number.

[CODE]
void IOSearchString()
{
string SearchString, InputFilePath, OutputFilePath, InputFileLine;

cout << "Welcome!" << endl
     << "Please enter a string you wish to find:" << endl;
cin >> SearchString;

cout << endl << "Please enter the input file's path and name" << endl
     << "(e.g c://InputFilePath//InputFileName.txt)" << endl;
cin >> InputFilePath;

ifstream InputFile(InputFilePath);
if(!InputFile.is_open() || InputFile.bad())
{
    cout << endl << "Error! Failed to open: " + InputFilePath << endl;
    system("Pause");
    exit(1);
}

cout << endl << "Please enter the output file's path and name:" << endl;
cin >> OutputFilePath;

ofstream OutputFile(OutputFilePath);
if(!OutputFile.is_open() || OutputFile.bad())
{
    cout << endl << "Error! Failed to create/find: " + OutputFilePath << endl;
    system("Pause");
    exit(1);
}

if(InputFile.good() && OutputFile.good())
{
    int CountFound = 0;
    cout << endl << "Searching for: " + SearchString << endl;
    for(int LineCount = 1; getline(InputFile, InputFileLine); ++LineCount)
    {
        for(int i = 0; i != InputFileLine.length(); ++i)
        {
            if(InputFileLine.substr(i, SearchString.length()) == SearchString)
            {
                OutputFile << "Line " << LineCount << ":" << InputFileLine << endl;
                i = InputFileLine.length() - InputFileLine.substr(i, SearchString.length()).length();
                ++CountFound;
            }
        }
    }
    cout << endl << "Searching completed!" << endl;

    if(CountFound <= 0)
    {
        cout << "Found: 0" << endl;
    }
    else if(CountFound > 0)
    {
        cout << "Found: " << CountFound << endl;
    }
}
else
{
    cout << endl ...

I am currently in high school and I am also learning c++ (noobie).
I was interested in this thread because, I have never tried coding a function that could search a string in an input file and output the results into an output file. This is my first attempt.

This piece of code may look difficult because of its size...but its actually very simple and logic.

[CODE]
void IOSearchString()
{
string SearchString, InputFilePath, OutputFilePath, InputFileLine;

cout << "Welcome!" << endl
     << "Please enter a string you wish to find:" << endl;
cin >> SearchString;

cout << endl << "Please enter the input file's path and name" << endl
     << "(e.g c://InputFilePath//InputFileName.txt)" << endl;
cin >> InputFilePath;

ifstream InputFile(InputFilePath);
if(!InputFile.is_open() || InputFile.bad())
{
    cout << endl << "Error! Failed to open: " + InputFilePath << endl;
    system("Pause");
    exit(1);
}

cout << endl << "Please enter the output file's path and name:" << endl;
cin >> OutputFilePath;

ofstream OutputFile(OutputFilePath);
if(!OutputFile.is_open() || OutputFile.bad())
{
    cout << endl << "Error! Failed to create/find: " + OutputFilePath << endl;
    system("Pause");
    exit(1);
}

if(InputFile.good() && OutputFile.good())
{
    int CountFound = 0;
    cout << endl << "Searching for: " + SearchString << endl;
    for(int LineCount = 1; getline(InputFile, InputFileLine); ++LineCount)
    {
        for(int i = 0; i != InputFileLine.length(); ++i)
        {
            if(InputFileLine.substr(i, SearchString.length()) == SearchString)
            {
                OutputFile << "Line " << LineCount << ":" << InputFileLine << endl;
                i = InputFileLine.length() - InputFileLine.substr(i, SearchString.length()).length();
                ++CountFound;
            }
        }
    }
    cout << endl << "Searching completed!" << endl;

    if(CountFound <= ...
Tygawr -12 Newbie Poster

Hello everyone,

I am having a hard time reading and writing a UTF-8 file in visual c++ 2010.

[CODE]
void ReadUTF8File()
{
ifstream UTF8File("C:\DaniWeb\Desktop\UTF8File.txt");
/
UTF8File.txt:
☺☻♥♦♣♠•◘○
/
string UTF8FileStr;

if(UTF8File.is_open())
{
    while(!UTF8File.eof())
    {
        UTF8File >> UTF8FileStr;
        cout << UTF8FileStr << endl;
        /*
        cout:
        ☺☻♥♦♣♠•◘○
        */
    }
}
UTF8File.close();

}
[/CODE]

The output was not similar to the file's text. Please help, thank you for your time and consideration.