|
You don't need strtok for dealing with std::string . Use std::string.find instead. For instance
#include <string>
#include <iostream>
void main()
{
const int SIZE = 10;
std::string s[SIZE];
std::string str = "Hello folks, welcome!";
int i;
int start_pos, end_pos = 0;
for (i = start_pos=0; i <SIZE && (end_pos = str.find(' ', start_pos)) != std::string::npos; i++)
{
s[i] = str.substr(start_pos, end_pos-start_pos+1);
start_pos=end_pos+1;
}
if ( start_pos < str.length() && i < SIZE)
{
s[i] = str.substr(start_pos, str.length()- start_pos+1);
i++;
}
for (int j=0; j<i; j++)
{
std::cout << "s[" << j << "]=" << s[j] << std::endl;
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
NarVish wrote: Can we convert the string to char * type.
Try:
const char* cstr = str.c_str();
string first = strtok(cstr, "C");
Or just the simple
string first = strtok(str.c_str(), "C");
[EDIT]Or, just use CP's solution[/EDIT]
|
|
|
|
|
Whit CString s, for instance, your best bet is the Tokenize method [^], some extra work is required, however.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
this drives me nuts...
I have the following function that checks against an IP address control for displaying an error message box if users specify an invalid IP value that greater than 255
ON_NOTIFY(IPN_FIELDCHANGED, IDC_EDIT_LISTEN_ADDRESS, &CNetworkBindingDlg:SurprisenEditListenAddressChanged)
void CNetworkBindingDlg:SurprisenEditListenAddressChanged(NMHDR* pNMHDR,LRESULT* pResult)
{
LPNMIPADDRESS pIPAddr = reinterpret_cast<LPNMIPADDRESS>(pNMHDR);
if(pIPAddr->iValue > 255)
{
CStringW ErrMsg;
ErrMsg.Format(ResourceString(IDS_INVALID_IP_ADDRESS),pIPAddr->iValue);
MessageBox(ErrMsg,ResourceString(AFX_IDS_APP_TITLE), MB_ICONERROR);
}
}
Somehow the MessageBox() function execute twice. I chased the code and noticed that the MessageBox() is executed the first time, but the message does not show up, but the execution control comes back to the CStringW ErrMsg line, the MessageBox() will be executed the second time. And then the message box dialog shows up twice.
Any suggestion?
thanks.
|
|
|
|
|
yes, one suggestion. what's this ResourceString function. Check if there's some event happening that is sending ON_NOTIFY twice. THere can be more than one reason why OnNotify is called..
|
|
|
|
|
Hello,
I have xl5en32.h type library for automation . The header file contains classes like
appliction
workbooks
workbook
charts
chart
I have gone through the example of drawing charts in VC++ using automation . In each example they have the following code
_Application app;
_Workbook newBook;
Workbooks books;
Worksheets sheets;
_Worksheet newSheet;
Charts charts;
_Chart newChart;
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Create Excel server (start Excel)
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Can’t start Excel server!");
return;
}
app.put_Visible(true); //set Excel visible
app.put_UserControl(TRUE); //user can operate Excel
books = app.get_Workbooks();
newBook=books.Open("C:\\mynew.xls",vOpt, vOpt, vOpt, vOpt, vOpt,
vOpt, vOpt, vOpt, vOpt, vOpt,vOpt, vOpt,vOpt,vOpt);
newBook = books.Add(vOpt);
sheets = newBook.get_Sheets();
newSheet = sheets.get_Item(COleVariant((short)1));
charts = newBook.get_Charts();
------------------------------------------------
but the above classes are are missing in xl5en32.h type library
and all the functions return COleVariant
How shd i go about writing code for charts ?
Prithaa
|
|
|
|
|
I am trying to replace
if(watever)
somecode;
with
if(watever)
{
somecode;
}
(if\([^`]*\))([ \n])([^`]*[;])
This regex finds out all such if blocks but when I try to replace \3 with {\3}, I get nothing; meaning \1, \2, \3 are just empty. \0 has value and it is equal to the complete string found.
I expect
\1 = (if\([^`]*\))
\2 = ([ \n])
\3 = ([^`]*[;])
It may be obvious by now that this is the first time I am using regex. Please suggest.
|
|
|
|
|
Visual studio Tag expression is {} and not (). If I use {} instead of (), I get correct values in %1, %2.
Any idea how can I properly indent the inserted brackets. THey are inserted at start of line whereas 'if' can be indented?
|
|
|
|
|
Hi All
Can i save change excel *.xls to *.xlsx?
|
|
|
|
|
Please help me some one..
|
|
|
|
|
yes.. you can change the extension by using as Save As option
|
|
|
|
|
thanks for reply .I know that change the extension by using as Save As option.But how it is possible through code.
|
|
|
|
|
Hi,
I have a interface to interact with MS-Access database file. I m using CODBCRecordset for accessing DB.
CODBCRecordset class[^]
It was working fine untill I added new field in one of the table.
I added new field ("Lock1" - a integer field) in table (called "Quotation_DB").
This table have bunch of data (int,double,strings). I have a button in my interface which will set this "Lock1" field to 0/1 in separate function. when i click this button i get following error.
//==================
Expression too complex
Expression too complex
//==================
yes it is printing same message twice.
any kind of help will be good to me. Please let me know if i have to provide more information.
This is what i m doing in my function.
BOOL LockUnlockQuotation(BOOL flg_lock)
{
CODBCRecordset m_RS_RFQ(&DataBase);
BOOL flg_update = false;
if( !m_RS_RFQ.Open("SELECT * FROM \"Quotation_DB\"") )
{
TRACE("Failed to run query: \"%s\"\n","SELECT * FROM \"Quotation_DB\"");
return false;
}
else
{
if(!m_RS_RFQ.IsEOF())
{
m_RS_RFQ.MoveFirst();
}
CString Quot_revID_db="";
while(!m_RS_RFQ.IsEOF())
{
Quot_revID_db=m_RS_RFQ.GetString("QuotID");
if(Quot_revID.Compare("MyQoute2009")==0)
{
m_RS_RFQ.Edit();
m_RS_RFQ.Field("Lock")=1;
m_RS_RFQ.Update();
flg_update =true;
break;
}
m_RS_RFQ.MoveNext();
}
m_RS_RFQ.Close();
}
return flg_update;
}
modified on Wednesday, September 23, 2009 3:08 PM
|
|
|
|
|
is there any fix for this?
modified on Wednesday, September 23, 2009 2:59 PM
|
|
|
|
|
Hi,
I have a interface to interact with MS-Access database file. I m using CODBCRecordset for accessing DB.
CODBCRecordset class[^]
It was working fine untill I added new field in one of the table.
I added new field ("Lock1" - a integer field) in table (called "Quotation_DB").
This table have bunch of data (int,double,strings). I have a button in my interface which will set this "Lock1" field to 0/1 in separate function. when i click this button i get following error.
//==================
Expression too complex
Expression too complex
//==================
yes its print same message twice.
any kind of help will be good to me. Please let me know if i have to provide more information.
This is what i m doing in my function.
BOOL LockUnlockQuotation(BOOL flg_lock)
{
CODBCRecordset m_RS_RFQ(&DataBase);
BOOL flg_update = false;
if( !m_RS_RFQ.Open("SELECT * FROM \"Quotation_DB\"") )
{
TRACE("Failed to run query: \"%s\"\n","SELECT * FROM \"Quotation_DB\"");
return false;
}
else
{
if(!m_RS_RFQ.IsEOF())
{
m_RS_RFQ.MoveFirst();
}
CString Quot_revID_db="";
while(!m_RS_RFQ.IsEOF())
{
Quot_revID_db=m_RS_RFQ.GetString("QuotID");
if(Quot_revID.Compare("MyQoute2009")==0)
{
m_RS_RFQ.Edit();
m_RS_RFQ.Field("Lock")=1;
m_RS_RFQ.Update();
flg_update =true;
break;
}
m_RS_RFQ.MoveNext();
}
m_RS_RFQ.Close();
}
return flg_update;
}
|
|
|
|
|
is there any fix for this?
modified on Wednesday, September 23, 2009 2:59 PM
|
|
|
|
|
UNIT SimpleThread::ThreadFunc(LPARAM lp)
{
While(1)
{
printf("Test");
}
}
SimpleThread::Start()
{
DWORD dwThreadId, dwThrdParam = 1;
threadHandle = CreateThread(
NULL,
0,
SimpleThread::ThreadFunc,
dwThrdParam,
0,
&dwThreadId);
}
When call the thread it does't get called. Also somtimes it called but the while loop terminate within a while.Can any give me solution to this
|
|
|
|
|
VVVimal wrote: SimpleThread::Start()
What happens to the main thread after the creation of the thread?
|
|
|
|
|
AFAIK,
we cannot use a normal member function of a class as a thread.
there is a different procedure for this, let me remember.
but as a temporary solution, i can suggest you to use ThreadFunc as a global function and see.
good luck.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
UNIT SimpleThread::ThreadFunc(LPARAM lp)
{
While(1)
{
printf("Test");
}
}
SimpleThread::Start()
{
DWORD dwThreadId, dwThrdParam = 1;
threadHandle = CreateThread(
NULL,
0,
SimpleThread::ThreadFunc,
dwThrdParam,
0,
&dwThreadId);
}
When call the thread it does't get called. Also somtimes it called but the while loop terminate within a while.Can any give me solution to this
|
|
|
|
|
How can you even compile your code (there are a lot of errors)?
The following one works properly
#include <windows.h>
class SimpleThread
{
static DWORD WINAPI ThreadFunc(LPVOID p)
{
while(1)
{
printf("Test");
}
}
public:
void SimpleThread::Start()
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE threadHandle;
threadHandle = CreateThread(
NULL,
0,
ThreadFunc,
&dwThrdParam,
0,
&dwThreadId);
}
};
void main()
{
SimpleThread t;
t.Start();
while (1);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello, everyone
I've wrote a code which will find the intersection of two given Linked lists sorted in increasing order.
Actually the code is running fine now, but I find a problem during compiling, but I dont know the reason,
so, hope someone know what's cause the problem. Thank you!
Problem is, if I put /* dummy.next = NULL; */ in front of /* struct node* tail = &dummy; */,
there will be errors, otherwise, problem running fine. Following is the function I wrote.
Thank you all.
// create a new list with the intersection of two given lists sorted in increasing order
struct node* SortedIntersect(struct node* head1, struct node* head2)
{
struct node dummy;
struct node* tail = &dummy;
dummy.next = NULL;
while(head1 != NULL && head2 != NULL)
{
if(head1->data == head2->data)
{
Push(&(tail->next), head1->data);
tail = tail->next;
head1 = head1->next;
head2 = head2->next;
}
else if(head1->data > head2->data)
{
head2 = head2->next;
}
else
{
head1 = head1->next;
}
}
return dummy.next;
}
modified on Wednesday, September 23, 2009 2:35 PM
|
|
|
|
|
is this C or C++?
In C, all the variable declaration should be wrttien in the begining of the function before any other code.
|
|
|
|
|
I am attempting to write some atomicInc functions that take 16 or 32 bit signed arguments, and call the appropriate _InterlockedIncrement intrinsic function when compiled in Visual Studio 2008. However, it appears the function _InterlockedIncrement takes a 64-bit integer on my system (Windows XP SP2 64-bit Pro), even though the documentation states that _InterlockedIncrement is the 32-bit version of the function call.
My question is, what intrinsic should I use to atomically increment a 32-bit value? The following is producing an error:
#include <intrin.h>
#pragma intrinsic (_InterlockedIncrement, _InterlockedIncrement16)
__int16 atomicInc(__int16 *val) {
return _InterlockedIncrement16(val);
}
__int32 atomicInc(__int32 *val) {
return _InterlockedIncrement (val);
} Any help is greatly appreciated. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
modified on Tuesday, September 22, 2009 5:37 PM
|
|
|
|
|
A failing on MS part i think.
http://msdn.microsoft.com/en-us/library/29dh1w7z(VS.80).aspx[^]
__in32 == int, int != long (as data types are concerned).
They should have made __int32 == long.
You have 2 choices:
__int32 atomicInc(__int32 *val) {
return (__int32)_InterlockedIncrement((long*)val);
}
or
__int32 atomicInc(long *val) {
return (__int32)_InterlockedIncrement(val);
}
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|