Avatar billede ittraffic Nybegynder
13. august 2007 - 10:08 Der er 2 kommentarer

Read data

Hej Eksperten brugere,

Jeg ønsker hjælp til at få dette opgave løst.

Det jeg ønsker er at hente data fra en txt fil fra nettet.

http://localhost/test.txt indeholder "Plantagen;4;8400;Ebeltoft;"

Dette ville jeg gerne have placeret i min c++ kode som er vist (Array01 skal placeret i aStreet = "Randers" osv.):

// ExampleManualDlg.cpp : implementation file
//
#include <iostream>
#include <sstream>
#include <fstream>
#include "stdafx.h"
#include "ExampleManual.h"
#include "ExampleManualDlg.h"

#include "sdkconstants.h"
#include "TomTomAPI.h"
#include "TomTomGoFileLayer.h"
#include <stdio.h>
#include <string>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define CLIENT_NAME "client"

int res;
CString str;
CString strout;
CTomTomAPI::TError err;
CTomTomAPI::TVersion version;
CTomTomAPI::TGeocodeResult GeoRes;
char  *aCity;
char  *aStreet;
char  *aNumber;
char  *aPostCode;



/////////////////////////////////////////////////////////////////////////////
// CExampleManualDlg dialog

CExampleManualDlg::CExampleManualDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CExampleManualDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CExampleManualDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CExampleManualDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CExampleManualDlg)
    DDX_Control(pDX, IDC_Result, m_EditResult);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CExampleManualDlg, CDialog)
    //{{AFX_MSG_MAP(CExampleManualDlg)
    ON_BN_CLICKED(IDC_BUTTONTT, OnButtontt)
    ON_BN_CLICKED(IDC_AppVersion, OnAppVersion)
    ON_BN_CLICKED(IDC_DevID2, OnDevID2)
//    ON_BN_CLICKED(IDC_Geocode, OnGeocode)
    ON_BN_CLICKED(IDC_DataSet, OnDataSet)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExampleManualDlg message handlers

BOOL CExampleManualDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
   
    CenterWindow(GetDesktopWindow());    // center to the hpc screen

    // TODO: Add extra initialization here
   
    return TRUE;  // return TRUE  unless you set the focus to a control
}



void CExampleManualDlg::OnButtontt()
{
   
    MTomTomCommunicationLayerInterface *comms =
                  DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
    CTomTomAPI api(*comms);
   

    aCity = "Randers";
    aStreet = "Urtevangen";
    aNumber = "9";
    aPostCode = "8900";
   
    res = api.NavigateToAddress(&err,&*aCity,&*aStreet,&*aNumber,&*aPostCode);
    res = api.BringNavigatorToForeground(&err);
       
    strout = "";
      str.Format(_T("Geocode = %d\r\n"), res);
      strout = strout + aStreet + " | "  + aNumber + " | "  + aPostCode + " | "  + aCity;
      m_EditResult.SetWindowText(strout);
   
    delete comms;
   
}

void CExampleManualDlg::OnAppVersion()

{   
    MTomTomCommunicationLayerInterface *comms =
                  DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
    CTomTomAPI api(*comms);
    res = api.GetApplicationVersion(&err, &version);
    str.Format(_T("Result: %d\r\nBuildnumber: %d\r\nVersion: %S\r\n "), res, version.iBuildNumber ,  version.iVersion);
    m_EditResult.SetWindowText(str);   
    delete comms;
}

void CExampleManualDlg::OnDevID2()
{
    MTomTomCommunicationLayerInterface *comms =
                  DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
    CTomTomAPI api(*comms);

  if(api.IsApplicationRunning(&err) == false)
    api.StartApplication(&err);

    MTomTomSession *mysession;
    mysession = api.GetUniqueDeviceIdAsync(true);
    m_EditResult.SetWindowText(str);
    int sum = 0;
    while(!(comms -> ReturnAvailable(mysession)))
    { 
        sum++; 
    }
    CTomTomAPI::TDeviceId resultid;
    res = api.GetUniqueDeviceIdAsyncRetrieve(mysession , &err, &resultid);
    str.Format(_T("Result: %d\r\nCounted until: %d\r\nIDLength = %d\r\nID = %S\r\n "), res, sum, resultid.iDeviceIdLength ,  resultid.iDeviceId);
    m_EditResult.SetWindowText(str);
    delete comms;
}

void CExampleManualDlg::OnDataSet()
{

    MTomTomCommunicationLayerInterface *comms =
                  DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);

  CTomTomAPI api(*comms);

  if(api.IsApplicationRunning(&err) == false)
    api.StartApplication(&err);

    comms->StartSendCommand(); 
    comms->AppendArgument("GetDataSetInfoV01");
    MTomTomSession* session = comms->SendCommand(); 
    int sum = 0; 
      while(!(comms ->ReturnAvailable(session))) 
      {     
        sum++;
      } 
      comms->StartReceiveCommand(session); 
      int  nfields; 
      nfields = comms->NrReceiveFields(); 
      strout = "";
      str.Format(_T("Number of Fields = %d\r\n"), nfields);
      strout = strout + str ;
      m_EditResult.SetWindowText(str);
      int index=0; 
      for (index=0;index<nfields;index++)         
      {  str.Format(_T("Index %d : %S\r\n"),index, comms->ReceiveField(index));
        strout = strout + str ;   
      }
    m_EditResult.SetWindowText(strout);
    delete comms;     
}
Avatar billede ittraffic Nybegynder
13. august 2007 - 10:09 #1
En tilføjelse!

Koden skal gerne laves i gruppen:

void CExampleManualDlg::OnButtontt()
{
   
    MTomTomCommunicationLayerInterface *comms =
                  DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
    CTomTomAPI api(*comms);
   

    aCity = "Randers";
    aStreet = "Urtevangen";
    aNumber = "9";
    aPostCode = "8900";
   
    res = api.NavigateToAddress(&err,&*aCity,&*aStreet,&*aNumber,&*aPostCode);
    res = api.BringNavigatorToForeground(&err);
       
    strout = "";
      str.Format(_T("Geocode = %d\r\n"), res);
      strout = strout + aStreet + " | "  + aNumber + " | "  + aPostCode + " | "  + aCity;
      m_EditResult.SetWindowText(strout);
   
    delete comms;
   
}
Avatar billede soepro Nybegynder
27. august 2007 - 12:33 #2
Hej ittrafic !

Er det "bare" indlæsning af tekst-filen og tildeling af det indlæste indhold du er ude efter - eller skal du også bruge noget kode der henter filen fra nettet ?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester