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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:48+00:00 2026-05-25T18:14:48+00:00

I’m not entirely familiar with how CLI works, but I have a general idea.

  • 0

I’m not entirely familiar with how CLI works, but I have a general idea. I have a function that takes 2 System::String variables, and uses those to download a file from a webpage. As far as the download goes, it works fine, and the file shows up in my directory with the necessary content. However, it gives me the error

An unhandled exception of type ‘System.AccessViolationException’
occurred in ParseLinks.exe

void downloadFile(System::String ^_URL, System::String ^_saveAs)
{
    try
    {
        System::Net::WebClient ^webClient = gcnew System::Net::WebClient();
        // Downloads the resource with the specified URI to a local file.
        webClient->DownloadFile(_URL, _saveAs);
        webClient->Dispose();
    }
    catch (System::Exception ^_e)
    {
        // Error
        System::Console::WriteLine("Exception caught in process: {0}", _e);
    }
}

I did some digging and output testing, and found out that the exe is hitting a break point somewhere in the text file, as the entire webpage did not save to the txt file.

Relevant code for that:

        if (myFile.is_open()) //if file open
        {
            while (!myFile.eof()) //before end of file
            {
                getline(myFile, ln);
                lines[count] = ln;
                count++; //count total lines to set loop length for later parsing
                //Error occurs somewhere in here
            }
            myFile.close();
        }
        else
            cout<<"Error: Could not access file\n";

Brand New Error! 🙁

An unhandled exception of type ‘System.Runtime.InteropServices.SEHException’ occurred in ParseLinks.exe

The code after the file -> line array loop

myFile.close(); //Close txt file

            //Loop through lines
            for (int i = 0; i < count; i++)
            {
                string temp = parseLinks(lines[i]); //parse links from each line

The function for that:

string parseLinks(string str)
{
    const int len = str.length();
    string link;
    bool quotes = false, islink = false;
    string compare[5] = {".htm",".html",".php",".asp",".pdf"};

    //Parse all quoted text
    for (int i = 0; i != len; i++)
    {
        //Change bool if quote found
        if (str[i] == '"')
        {
            if (quotes == false)
                quotes = true;
            else
                quotes = false;
        }

        //If bool true, and char is not a quote, add to link string
        if (quotes == true && str[i] != '"')
            link += str[i];
    }

    //Discard non-link text
    for (int i = 0; i < 5; i++)
    {
        //Link check for links given array of path filetypes
        if (link.compare((link.length() - compare[i].length()),compare[i].length(),compare[i]) == 0)
            islink = true;
    }
    //Link check for links with no path filetype (.html, .php, etc.)
    if (link.compare(0,7,"http://") == 0)   
        islink = true;

    //If not a link, return empty string
    if (islink == false)
        link = "";

    return link;
}

The error points to my large compare statement in this function. (Also, I’m clearly terrible at compressing my code)

  • 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-05-25T18:14:49+00:00Added an answer on May 25, 2026 at 6:14 pm

    You’re using getline wrong, and possibly that’s causing your error. The correct idiom is this:

    std::string line;
    while (std::getline(myFile, line))
    {
      // process `line`
    }
    

    There’s no need to check myFile for openness separately.

    • 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
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I want to construct a data frame in an Rcpp function, but when I

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.