C++ 数组太大?将大文件读入数组C++;

C++ 数组太大?将大文件读入数组C++;,c++,arrays,visual-studio-2010,C++,Arrays,Visual Studio 2010,下面是我的代码,虽然不太漂亮,但在很多情况下都能正常工作。 我遇到了这样一个问题,当我试图将这个文件(由这个程序下载)读入数组,然后对数组进行一些分析时,它显示了这个错误: projecti.exe中0x00a7c197处未处理的异常:0xC00000FD:堆栈溢出。 我觉得代码没有问题。是阵列的大小超出了内存容量吗? 或者,您是否建议更好地使用文件进行分析,而无需将其读入数组? 谢谢非常感谢您的帮助 #include <string> #include <iostream&g

下面是我的代码,虽然不太漂亮,但在很多情况下都能正常工作。
我遇到了这样一个问题,当我试图将这个文件(由这个程序下载)读入数组,然后对数组进行一些分析时,它显示了这个错误:

projecti.exe中0x00a7c197处未处理的异常:0xC00000FD:堆栈溢出。

我觉得代码没有问题。是阵列的大小超出了内存容量吗?

或者,您是否建议更好地使用文件进行分析,而无需将其读入数组?
谢谢非常感谢您的帮助

#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <wininet.h>
#include <winsock.h>
#include <stdio.h>

#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& 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 << "Error in opening internet" << endl;
        return 0;
    }           
    hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 );                                    

    ofstream fout("RSS_archieve_download.txt");
    InternetReadFile(hURL, file, file_l, &read);

    int i = 0;
    while (read > 0)
    {                                                                                           
        file[read] = '\0';
        fout << file;
        InternetReadFile(hURL, file, file_l, &read);
        i+=1;
    }
    fout.close();
    cout << endl;
    InternetCloseHandle(hURL);
    return 0;
}

int read_file(string webpage[])
{ 
    ifstream fin("RSS_archieve_download.txt");
    if (fin.fail())
    {
        cout << "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 << "Failed to open RSS_archieve_urls\n";
        exit(1);
    }
    int i = 0;
    while(true)
    {
        fin >> url_list[i];
        if (fin.fail())
        break;
        i+=1;
    }
    fin.close();

    ofstream fout("R2_url.txt");
    for(int j = 0; j < 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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#pragma注释(lib,“wininet.lib”)
使用名称空间std;
const int file_l=100;
const int file_length=40000;
const int sam_url_num=1;
wstring s2ws(常量字符串和s)
{
内伦;
int slength=(int)s.length()+1;
len=MultiByteToWideChar(CP_ACP,0,s.c_str(),slength,0,0);
wchar_t*buf=新的wchar_t[len];
MultiByteToWideChar(CP_ACP,0,s.c_str(),slength,buf,len);
WSTR环(buf);
删除[]buf;
返回r;
}
int下载url(字符串url)
{   
腹地霍本,投掷;
LPCWSTR NameProgram=L“Webreader”;
wstring stemp=s2ws(url);
LPCWSTR网站=stemp.c_str();
字符文件[file_l+1];
无符号长读;
if(!(hOpen=InternetOpen(名称程序、INTERNET\u打开\u类型\u预配置、NULL、NULL、0)))
{

cerr向量更适合于处理大量数据和大量代码的容器

这是一个psuedo RSS提要阅读器

#include <fstream>
#include <string>
#include <vector>
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) 
{
    vector<string> rssfeeds;

    string rssline;
    ifstream rssfile("rss.txt");
    int i=0;
    cout<<"RSS -----------------\n\n";

    while(getline(rssfile, rssline)) 
    {

        rssfeeds.push_back(rssline);


    }
    rssfile.close();

    for (i=0;i<rssfeeds.size();i++)
    {
        cout<<rssfeeds[i]<<"\n";
    }

    return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main(int argc,char*argv[])
{
矢量rssfeeds;
字符串rssline;
ifstream rssfile(“rss.txt”);
int i=0;

可能在哪里发生错误?程序失败时如何运行?@ShafikYaghmour我真的不知道它在哪里失败。这会有帮助吗?**测试dword ptr[eax],eax;探测页。**字符串arr[40000]可能有问题。请改为尝试字符串*arr=新字符串[40000]。