|
If you aren't concerned with the '\n' character, strtok is what you are looking for.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
If you're using C++ (and probably even if you're using C) using strtok is bad form. It modifies the input string and isn't thread safe for a start. Avoid it like the plague. Here's how I'd do it in C++:
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace std;
const char message[] = "Line 1\nLine 2\nThe third and last line\n";
istringstream iss(message);
string line;
while (getline(iss, line))
{
cout << line << endl;
}
return 0;
}
Steve
|
|
|
|
|
Hey everybody
I'm not sure if I'm asking in the right place, so if not, please let me know .
I'm a c# programmer and I user to program a LONG LONG LONG in c++ just a little little bit.
so I have a very basic question because the compiler is shouting at me and I really don't get why.
I wrote an Employee class (just for a little trainning)
and thats what I wrote (I'm using VS2005):
Employee.h :
class Employee<br />
{<br />
public:<br />
int ID;<br />
float wadge;<br />
float hours;<br />
float overtime;<br />
<br />
Employee()<br />
{<br />
printf("initiallizing an Employee");<br />
}<br />
<br />
void show();<br />
<br />
private:<br />
<br />
double calcSalary();<br />
}
and my Employee.cpp:
<br />
#include <stdio.h><br />
#include "Employee.h"<br />
<br />
double Employee::calcSalary()<br />
{<br />
return (Employee::hours*Employee::wadge) + (Employee::overtime*Employee::wadge*1.5);<br />
}<br />
<br />
void Employee::show()<br />
{<br />
printf("Employee's ID: ", Employee::ID);<br />
}
but for some reason I'm getting these compiling errors:
1. 'Employee' followed by 'double' is illegal (did you forget a ';'?)
Where did I wrote "Employee" and than "double"???
2. 'Employee Employee::calcSalary(void)' : overloaded function differs only by return type from 'double Employee::calcSalary(void)'
as far as I understand I did not defined any "Employee Employee::calcSalary(void)" function.
3. error C2371: 'Employee::calcSalary' : redefinition; different basic types
huh?!
as you can see, I'm pretty lost!
help anyone???
Thanks!
|
|
|
|
|
Green Fuze wrote: class Employee
{
public:
int ID;
float wadge;
float hours;
float overtime;
Employee()
{
printf("initiallizing an Employee");
}
void show();
private:
double calcSalary();
}
you forget ";" after class declaration, it could be like this,
class Employee
{
public:
int ID;
float wadge;
float hours;
float overtime;
Employee()
{
printf("initiallizing an Employee");
}
void show();
private:
double calcSalary();
};
|
|
|
|
|
I didn't know I should've done that
Thanks!
|
|
|
|
|
One of the nasty little differences between C# and C++.
Kevin
|
|
|
|
|
Moving this thread to the Visual C++ forum!
|
|
|
|
|
Hi,
I have a progress bar and I set the range using
m_datprog.SetRange(0,Prog)
The problem I have is that the progress bar is full before it reaches the maximum limit (prog). Any help would be appreciated.
Thanks,
DS
|
|
|
|
|
Hi,
Are you using a timer with the progress bar?
Cause it sounds like you just set the progressbar, but never increment it?!
Regards
Programm3r
|
|
|
|
|
|
See CProgressCtrl::SetPos(...)
|
|
|
|
|
If you set the control's range with SetRange(0, 100) , and then call SetPos(125) part-way through some process, the control will indeed show 100% even though the process is not done. Does that sound like what you might have?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Does any one has the idea of the exact calculation for superscript and subscript style of font. I mean the font is shrinked in MSWord. What calculation is used ? and also the baseline are moved as well. What are the standard calculations behind it ?
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|
|
Hi, all
I encountered a problem about refreshing the system drivers in Device Manager. When installing a software, I registered 2 system virtual device into system. After the box restart again, those 2 drivers do not display in the "No Plug and Play Device" device node in the System Device manager(via "View" menu and "Show hidden devices"). It will always appear after running "Scan for Hardware Change" menu or the seconde time reboot.
I want to ask is there any Windows API or MSDN function can play the same role as "Scan for Hardware Change". I want to let Windows do the same job.
I tried the sending message way and it was failed. The following are my codes.
SendMessageTimeout(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED,0, SMTO_ABORTIFHUNG, 3000, &dwMsgResult);
Thanks for give me some suggestions.
|
|
|
|
|
I want to write a program in Visual C++ to transfer data between a computers and microcontroller.
I have to use the wireless communication between PC and Microcontroller.
What i need (libraries, or is there any help in MSDN.)
What i figured out is that i need "winsock" for programming.
Where should I start.
thanks
|
|
|
|
|
Hallo,
In my program, I execute some SQL-querys stored in a CString-variable. My question is: how long can this query be? Does this depend on the CString or on SQL?
Thaks, Gerhard
|
|
|
|
|
of course limitted by the SQL engine... by i never heard of a query maximum length size...
|
|
|
|
|
Thanks for the fast answer, Gerhard
|
|
|
|
|
Hi All,
I have been trying to build on an application that allows you to write to blogs. After googling and gathering information I have not been able to find a good resource that provides some articles on writing to blogs. I am using VC++ .NET
Can some body provide a URL where I can get some examples regarding publishing to blogs?
Any help is highly appreciated.
Thanks
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Thanks for your suggestion.
Can you tell me how can I use this API to write/publish the comments to blogger.com
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: Can some body provide a URL where I can get some examples regarding publishing to blogs?
Each blog uses a different API to do this. Almost all of them use an HTTP-XMLRPC type setup, but you will have to look at the documentation for each blog you want to write a client for to find out what they want/expect to be in the message. I would start with the open source blogs first (LiveJournal use to have a fairly extensive document that described their API in great detail ... I'm not sure if it is still there or if it is up to date, but it would be a good starting point).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for your comment. I already know that it would require an API for specific blog.I want to write to blogger.com
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I hava writen a DLL,and injected DLL into a process.But when I inject DLL into target process every time,it will terminate the target process.If I don't create a new thread in DLL,it work well.How can I write correct code to implement?
ps: testdll.cpp
#include "stdafx.h"
#include <afxdllx.h>
#include "process.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static AFX_EXTENSION_MODULE TestDLL = { NULL, NULL };
unsigned __stdcall ThreadFunc(LPVOID pParam){
CSocket sockListen,m_sockSend;
sockListen.Create(6802,SOCK_STREAM,"127.0.0.1");
sockListen.Bind(6802,"127.0.0.1");
sockListen.Listen(5);
sockListen.Accept(m_sockSend);
Sleep(50000);
sockListen.Close();
MessageBox(NULL,"ThreadFunc","Oops!!",MB_OK);
return 0;
}
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("Test.DLL !\n");
if (!AfxInitExtensionModule(TestDLL, hInstance))
return 0;
new CDynLinkLibrary(TestDLL);
_beginthreadex(NULL,0,ThreadFunc,NULL,0,NULL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("Test.DLL !\n");
AfxTermExtensionModule(TestDLL);
}
return 1;
}
|
|
|
|
|
perhaps I should write dll without MFC
|
|
|
|