Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

HELP ME!!! I can't input the value to matrix in Win32 app.

$
0
0

I am a student on a final project. I'm writing an apps that read from csv in win32 app. But I'm not using CStdioFile. I'm using ifstream. This is my code for reading

    time_t long_time;
    time(&long_time);
    tm* st = localtime(&long_time);

    string line;
    char get;
    int i;

    fstream opn;
    opn.open(path);
    for(i = 1; i <= jumlahdata; i++)
    {
        
        getline(opn, line,'\n');
        std::istringstream iss(line);
        
        iss >> st->tm_mon >> get >> st->tm_mday >> get >> st->tm_year >>
            st->tm_hour >> get >> st->tm_min >> get >> tinggi[i];
        st->tm_sec=0;
        st->tm_mon--;
        st->tm_year-=1900;
        waktu[i] = mktime(st);
    }
    opn.close()

This script work well in console app. But when I used it on the win32 app this script went error.

void CMainFrame::OnFileOpen40001()
{
    // TODO: Add your command handler code here
    CString str;
    //CRect rc;
    //string path;
        
    //CFile ifp;
    //fstream opn;
    CFileDialog FileDlg(true, _T("*.csv"), NULL,NULL, _T("Comma Separated Value|*.csv"));
    if (FileDlg.DoModal()==IDOK)
    {
        str=FileDlg.GetFolderPath();
        str+='\\'+FileDlg.GetFileName();
        //string path((LPCTSTR)str);
        // Convert a TCHAR string to a LPCSTR
        CT2CA pszConvertedAnsiString (str);
        // construct a std::string using the LPCSTR input
        //std::string path (pszConvertedAnsiString);
        string path (pszConvertedAnsiString);
        //opn.open(str);
        //ifp=fopen((str),"r");
        /*
        CFileException e;
        if(ifp.Open(str,CFile::modeRead))
            e.ReportError();
            */
        n = data::countdata(path);
        CString a;
        waktu = new int unsigned [n+1];
        tinggi = new double [n+1];
        data::readdata(path, waktu, tinggi, n);
        CClientDC dc(this);
        a.Format(_T(" Data tinggi = %d"),tinggi[1]);
        dc.TextOutW(250,250,str);
        dc.TextOutW(250,350,a);
        
    }
}

Please help me. I can't figure the problem.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>