Note that there are some explanatory texts on larger screens.

plurals
  1. POString stream related problems
    primarykey
    data
    text
    <p>I am trying to do the following</p> <pre><code>std::stringstream str; string string1, string2; long a = 23343; long b = 323234; str &lt;&lt; std::hex &lt;&lt; a; str &gt;&gt; string1; //line no. 6 str &lt;&lt; std::hex &lt;&lt; b; str &gt;&gt; string2; //line no.8 </code></pre> <p>a &amp; b are values contained inside a structure and this structure is being sent as an event to other process, which extracts these values. The problem I encounter is when I do</p> <pre><code>str.flush() </code></pre> <p>after line no.6, the <code>string string1</code> is empty and an empty <code>string</code> is passed to other process.</p> <p>Is there any way to reuse the <code>stringstream str</code> for different values?</p> <p>Here is the actual code -- </p> <pre><code>void* CIAppDiagService::SendDidValue(void *arg) { DiagService::SReadDIDResponse didResponse; didResponse.ComponentId = ::DiagService::eComponentMin; //Todo didResponse.bStatus=false; didResponse.nDIDCode=((CIAppDiagService*)arg)-&gt;mDIDCode; if(didResponse.nDIDCode == 0xD95C) { ::CIApplicationManager::UUIDList_var aUidList; //get uuid list AppMgrServerData::getAppMgrServerData()-&gt;AppDirectory().getList(aUidList.out()); //fills the UUIDList which is a sequence of string if(aUidList-&gt;length() &gt; 0) { std::string aAppDetails,aAppVersion,aAppVersionString,aAppIDString,NumberOfAppsInstalledString; AppId aAppId; //typedef long AppId CORBA::ULong ulength = aUidList-&gt;length(); std::stringstream stream,stream1,stream2; short int iAppVersion; aAppDetails.append("000000ff"); short int iNumberOfAppsInstalled = AppMgrServerData::getAppMgrServerData()-&gt;AppDirectory().getTotalAppsInstalled(); // returns and integer stream &lt;&lt; std::hex &lt;&lt; iNumberOfAppsInstalled; stream &gt;&gt; NumberOfAppsInstalledString; stream.clear(); if(1 == NumberOfAppsInstalledString.length() ) { NumberOfAppsInstalledString = "000" + NumberOfAppsInstalledString; } else if(2 == NumberOfAppsInstalledString.length() ) { NumberOfAppsInstalledString = "00" + NumberOfAppsInstalledString; } else if(3 == NumberOfAppsInstalledString.length() ) { NumberOfAppsInstalledString = "0" + NumberOfAppsInstalledString; } strcat(const_cast&lt;char*&gt;(aAppDetails.c_str()),NumberOfAppsInstalledString.c_str()); for(int count = 0; count&lt; aUidList-&gt;length(); count++) { aAppId = AppMgrServerData::getAppMgrServerData()-&gt;AppDirectory().getApplicationAppIDByUid((aUidList[count])); aAppVersion = AppMgrServerData::getAppMgrServerData()-&gt;AppDirectory().getAppVersion(string(aUidList[count])); stream1 &lt;&lt; std::hex &lt;&lt; aAppId % (std::numeric_limits&lt;uint16_t&gt;::max()+1); stream1 &gt;&gt; aAppIDString; //convert aAppID into string stream1.clear(); strcat(const_cast&lt;char*&gt;(aAppDetails.c_str()),aAppIDString.c_str()); TRACE(cout&lt;&lt;"check 1"&lt;&lt;endl); iAppVersion = atoi(aAppVersion.c_str()); stream2 &lt;&lt; std::hex &lt;&lt; aAppVersion; TRACE(cout&lt;&lt;"CIAppDiagService::: SendDidValue::: aAppVersion stream = "&lt;&lt; stream2 &lt;&lt; endl); stream2.seekg(0, std::ios::beg); stream2 &gt;&gt; aAppVersionString; stream2.clear(); //The following is some restriction/implementation that i need to follow. if(1 == aAppVersionString.length() ) { aAppVersionString = "000" + aAppVersionString; } else if(2 == aAppVersionString.length() ) { aAppVersionString = "00" + aAppVersionString; } else if(3 == aAppVersionString.length() ) { aAppVersionString = "0" + aAppVersionString; } strcat(const_cast&lt;char*&gt;(aAppDetails.c_str()),aAppVersionString.c_str()); //aAppVersion concatenated } int length = strlen(aAppDetails.c_str()) + 1; if(length) { didResponse.DIDValue.length(length); for(int i=0; i &lt; length; i++) { didResponse.DIDValue[i]=aAppDetails[i]; cout&lt;&lt;" CIAppDiagService::SendDidValue:: didResponse.DIDValue[i]"&lt;&lt;didResponse.DIDValue[i]&lt;&lt;endl; } // didResponse.DIDValue[length] = '\0'; didResponse.bStatus = true; } else { char errResult[]={0x7F,0x22,0x22}; //error codes from media team/to be changed didResponse.DIDValue.length(3); didResponse.bStatus=false; for(int i=0; i&lt;3; i++) { didResponse.DIDValue[i]=errResult[i]; } } ((CIAppDiagService*)arg)-&gt;SendEvent_ResponseDidValue(didResponse); } else { cout&lt;&lt;" No applications installed/No AppIDs found. "&lt;&lt;endl; } } return 0; </code></pre> <p>}</p> <pre><code>void CIAppDiagService::SendEvent_ResponseDidValue(DiagService::SReadDIDResponse didResponse) { TRACE(cout&lt;&lt;"CIAppDiagService::entered in Send_Event Response"&lt;&lt;endl); CosNotification::StructuredEvent event; event.header.fixed_header.event_type.domain_name = CORBA::string_dup(DiagService::gDiagnosisServiceDomain); event.header.fixed_header.event_name = CORBA::string_dup(DiagService::gReadDIDEventName); event.header.variable_header.length(0); // put nothing here event.filterable_data.length(0); DiagService::SReadDIDResponse *tmp = new DiagService::SReadDIDResponse; if (tmp != NULL) { tmp-&gt;ComponentId = didResponse.ComponentId; //TODO tmp-&gt;DIDValue = didResponse.DIDValue; tmp-&gt;bStatus = didResponse.bStatus; tmp-&gt;nDIDCode = didResponse.nDIDCode; event.remainder_of_body &lt;&lt;= *tmp; TRACE(cout&lt;&lt;"CIAppDiagService::SendEvent_ResponseDidValue:: calling send event"&lt;&lt; endl); mCIDiagSupplier-&gt;send_event(event); } TRACE(cout&lt;&lt;"CIAppDiagService::exited from Send_Event Response"&lt;&lt;endl); </code></pre> <p>}</p> <p>The idea is to concatenate all strings into a string appDetails and fill the structure member SReadDIDResponse.DIDValue And here is the structure SReadDIDResponse</p> <pre><code>struct SReadDIDResponse { EComponent ComponentId; //enum values TID nDIDCode; // integer OctetSeq DIDValue; //octet sequence boolean bStatus; }; </code></pre>
    singulars
    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