Note that there are some explanatory texts on larger screens.

plurals
  1. POArray too big? reading a big file into array C++
    primarykey
    data
    text
    <p>Below is my code, it's not very pretty, but it works well in many cases.<br> I'm running into this question that when I'm trying to read this file(download by this program) into array, then do some analysis with the array, it shows this error:<br><br> <strong>Unhandled exception at 0x00a7c197 in projectII.exe: 0xC00000FD: Stack overflow.</strong><br></p> <p>I feel there is nothing wrong with the code. Is it the size of the array exceeds the memory capacity?<br><br> or do you suggest a better way to do analysis with a file without reading it into an array?<br> Thanks!! Any help is really appreciated!</p> <pre><code>#include &lt;string&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;windows.h&gt; #include &lt;wininet.h&gt; #include &lt;winsock.h&gt; #include &lt;stdio.h&gt; #pragma comment(lib, "wininet.lib") using namespace std; const int file_l = 100; const int file_length = 40000; const int sam_url_num = 1; wstring s2ws(const string&amp; s) { int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); wstring r(buf); delete[] buf; return r; } int download_url(string url) { HINTERNET hOpen, hURL; LPCWSTR NameProgram = L"Webreader"; wstring stemp = s2ws(url); LPCWSTR Website = stemp.c_str(); char file[file_l+1]; unsigned long read; if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ))) { cerr &lt;&lt; "Error in opening internet" &lt;&lt; endl; return 0; } hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 ); ofstream fout("RSS_archieve_download.txt"); InternetReadFile(hURL, file, file_l, &amp;read); int i = 0; while (read &gt; 0) { file[read] = '\0'; fout &lt;&lt; file; InternetReadFile(hURL, file, file_l, &amp;read); i+=1; } fout.close(); cout &lt;&lt; endl; InternetCloseHandle(hURL); return 0; } int read_file(string webpage[]) { ifstream fin("RSS_archieve_download.txt"); if (fin.fail()) { cout &lt;&lt; "Failed to open RSS_archieve_download.txt\n"; exit(1); } int i = 0; while (true) { getline(fin, webpage[i], '\n'); if (fin.fail()) break; i+=1; } fin.close(); } void multi_url(string webpage[], string url_list[])//final printout func { string url; ifstream fin("RSS_archieve_urls.txt"); if(fin.fail()) { cout &lt;&lt; "Failed to open RSS_archieve_urls\n"; exit(1); } int i = 0; while(true) { fin &gt;&gt; url_list[i]; if (fin.fail()) break; i+=1; } fin.close(); ofstream fout("R2_url.txt"); for(int j = 0; j &lt; i; j++) { url = url_list[j]; download_url(url); // read_file(webpage); } fout.close(); } int main() { string arr[file_length]; string sample_url[sam_url_num]; multi_url(arr, sample_url); system ("pause"); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload