|
i have this header for my class file and then .....
#include<vector>
using namespace std;
class bigNumber;
bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs);
bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs);
bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs);
ostream& operator<< (ostream& ostr, const bigNumber& t);
istream& operator>> (istream& istr, bigNumber& t);
class bigNumber{
public:
bigNumber();
bigNumber(const string & s);
bigNumber(vector<int> v);
friend bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs);
friend bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs);
friend bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs);
friend ostream& operator<< (ostream& ostr, const bigNumber& t);
friend istream& operator>> (istream& istr, bigNumber& t);
private:
vector<int> digits;
void reverse ();
};
i have these member functions coded so far but i need help with the input operator
bigNumber::bigNumber(){
}
bigNumber::bigNumber(const string& s){
for(int i= 0; i < s.length();i++)
digits.push_back(s[i] - '0');
}
bigNumber::bigNumber(vector<int> v){
for(int j = 0; j < v.size(); j++)
digits.push_back(v[j]);
}
bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
ostream& operator<< (ostream& ostr, const bigNumber& t){
for(int k = 0; k < (t.digits).size();k++)
ostr << t.digits[k];
return ostr;
}
istream& operator>> (istream& istr, bigNumber& t){
istr >> t.digits;
return istr;
}
when i leave the input operator like it is i get an error saying
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int=""> >' (or there is no acceptable conversion)
i dont know how to fix this and i am really pressed for time can someone please help me?
|
|
|
|
|
You can't do that. You need to iterate through the vector as you did for the output stream and pass each object through.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
char d;
if(istr >> d && isdigit(d))
t.digits.push_back(d - '0');
istr >> noskipws;
while(istr >> d && isdigit(d))
t.digits.push_back(d - '0');
istr >> skipws;
how come i keep getting the vector before added to the next vector if i input two numbers
??
|
|
|
|
|
d - '0' is a hack. Use atoi(d) instead.
What's going wrong ? Have you tried stepping through the code ? Why are you setting skipws instead of checking what the value of the flag is before you start ( so that you never change the state of the stream ) ? Why are there no brackets in the above code ? I'd expect you to just use a while loop for the entire code, not have the if at the start, and I'd expect all of the above code to be within the while loop, so if the first character is not a digit, none of it would run.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
my professor wants it the way that i have it right now. the reason is because you may press the enter key before inputting a number and it will still pickup the number.
that works, i figured out that i was missing a while loop. now it works fine and i am on to the arithmetic operators which i am having some trouble with.
thanks for all your help
very appreciative.
|
|
|
|
|
Anonymous wrote:
my professor wants it the way that i have it right now. the reason is because you may press the enter key before inputting a number and it will still pickup the number.
The initial character check, or the hack to use - '0' ?
Anonymous wrote:
that works, i figured out that i was missing a while loop
You're using a while loop to step through the vector ?
Anonymous wrote:
which i am having some trouble with.
Yeah, they are probably the stickiest bit, the iostream operators were pretty simple by comparison.
Did you read my iostream inserter/extractor article ? I forget the details, but there's definately stuff missing to make your code as good as it could be.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've made an OCX control. It works fine OK.
I want to instanciate that OCX when a .fbx file is dropped from file explorer on an Office application ... How can I do that?
Ex: In a PowerPoint slide I want to drop from file explorer myfile.fbx and this will instanciate
my FbxViewer.ocx in the PP slide and myfile.fbx will be loaded into my OCX control.
thanks
Danny
|
|
|
|
|
Can someone recommend a "Menu with icons" implementaiton that:
- works with MFC and ATL / WTL
- is least intrusive as possible
- works in both "classic" and "XP" look
I'd go with the "native" (MENUITEMINFO.hbmpItem, however, it looks terribly ugly)
There's an MFC solution here that loads a toolbarresource, and matches it with the ID's which I consider fairly clever, however it's MFC only and doesn't react lightly to changing the menu on the fly.
Suggestions?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
For some reason "status" field of Win32_Thread I am getting ThreadID. According to MS it should be status there like "OK", "Error", "Unknown", but I get in BSTR thread ID number. Just surprise is correct?
Thanks.
Alex.
|
|
|
|
|
I'm not sure where else to ask this so hear goes.
I have a file of about 14k in size. Its an Altera file to program an fpga.
I need to essentially split the file into chunks of 64 bytes, so I can use a specific function to send it through a usb device to our fpga.
Soooo how can I split a file of any size into chunks of 64 bytes?
|
|
|
|
|
By using an ifstream and an ofstream, just read 64 bytes at a time, and write off to files of your choosing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I make a C++/MFC (Version 6) application use the "Windows classic" look when running under Windows XP?
Thanks,
Alan
|
|
|
|
|
You shouldn't need to do anything special to make this happen.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
But when I run the application on XP, it uses the XP look: Blue shaded scroll bars (instead of the classic gray), faint group-box lines, etc...
It's possible to force an application to use the XP style. What I need is the opposite: Forcing the application to use the classic style.
Alan
|
|
|
|
|
Does the .exe contain an embedded manifest resource or an accompanying manifest file? See this[^] link (specifically the topic "To create a manifest and enable your application to use visual styles").
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks for the link, Ravi, but this seems to show how to force the application to use the XP visual style, which is the opposite of what I'm trying to do. Do you know how to modify this to use the Windows classic style?
Thanks,
Alan
|
|
|
|
|
Hi All,
Ok, this should be easy to figure out, but I can't seem to google a good answer. I need a way to programmatically discover the path to the current user's desktop. Something similar to GetWindowsDirectory() or GetSystemDirectory(), I guess.
The only think I could find was VBScript stuff like WshShell.SpecialFolders(...) or using the Windows Shell COM stuff.
There must be a simpler way to do this in C++, no?
TIA,
Pete
|
|
|
|
|
How about SHGetFolderPath(..., CSIDL_DESKTOPDIRECTORY, ...) ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
That'd do it!
Thanks David
|
|
|
|
|
I have a xml file that I need to copy to a folder near the $(TargetDir)
the custom build "Command Line" looks like this :
mkdir $(TargetDir)\..\MyFolder
copy $(ProjectDir)\myFile.xml $(TargetDir)\..\MyFolder\
and the "Output Line"
$(TargetDir)\..\MyFolder\myFile.xml
The problem is that everytime I execute ( F5 ) my program from VS.net, it asks me to "rebuild" that one file.
I understand that if a file is modified it should be compiled ( in my case copied ), but that file has not been modified for a couple of days.
Thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I want to write a spy program that will catch all messages of a window that I will choose... I want my program to return the ID's of the edit boxes, buttons, etc... Maybe anyone knows where I can start?
Thanks in advance!
Have a nice day!
|
|
|
|
|
Do you mean something like the Spy++ utility?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Help! I'm using MS Vis Studio 6 (with Vis C++ 6) and I don't really know where to begin. Does anyone know how I might make a simple script that would retrieve any given webpage (by inputting the URL) as some sort of string--like a CString, for instance. I am also behind a proxy, so I'm hoping that either whatever commands you give me automatically adjust to proxy settings or the code takes it into account (e.g. a place for inputting the proxy's IP and Port). Any advice is welcome. Thanks!
|
|
|
|
|
|
Hello,
I have a problem with my code that follows, everything works aye okay until I´m shutting the application down. My desktop resolution is then being set back to 1024x768x16 60Hz, and I have no idea why.
I´m aware that it´s quite alot of text to go through, but I would highly appreciate any suggestions on what might be wrong.
Edit:
The problem does not occur when I erase my ProcessIdle() function.
How come?
Thanks!
<br />
#include <iostream><br />
#include <windows.h><br />
#include <ddraw.h><br />
<br />
#include "resource.h"<br />
using namespace std;<br />
<br />
const char CLASS_NAME[] = "game_proj";<br />
const char WINDOW_NAME[] = "game_proj";<br />
<br />
const int ResX = 1024;<br />
const int ResY = 768;<br />
const int iColor = 32;<br />
<br />
HINSTANCE g_hInst = NULL;<br />
HWND g_hWnd = NULL;<br />
LPDIRECTDRAW7 g_pDD = NULL;<br />
<br />
LPDIRECTDRAWSURFACE7 g_lpDDSPrimary;<br />
LPDIRECTDRAWSURFACE7 g_lpDDSBack;<br />
<br />
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam,<br />
LPARAM lParam);<br />
BOOL InitiateWindow();<br />
BOOL InitiateDD();<br />
void ProcessIdle();<br />
void CleanUp();<br />
<br />
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int iCmdShow)<br />
{<br />
HWND hWnd;<br />
MSG msg;<br />
<br />
g_hInst = hInstance;<br />
InitiateWindow();<br />
<br />
hWnd = CreateWindow(CLASS_NAME,<br />
WINDOW_NAME,<br />
WS_POPUP,<br />
CW_USEDEFAULT,<br />
CW_USEDEFAULT,<br />
GetSystemMetrics(SM_CXSCREEN),<br />
GetSystemMetrics(SM_CYSCREEN),<br />
NULL,<br />
NULL,<br />
g_hInst,<br />
NULL);<br />
<br />
if(!hWnd)<br />
return 0;<br />
<br />
g_hWnd = hWnd;<br />
if(InitiateDD() < 0)<br />
{<br />
CleanUp();<br />
return 0;<br />
}<br />
<br />
ShowWindow(hWnd, iCmdShow);<br />
UpdateWindow(hWnd);<br />
<br />
while(true)<br />
{<br />
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br />
{<br />
if(msg.message == WM_QUIT)<br />
break;<br />
<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
else ProcessIdle();<br />
}<br />
<br />
return msg.wParam;<br />
}<br />
<br />
BOOL InitiateWindow()<br />
{<br />
WNDCLASSEX WndClass;<br />
<br />
WndClass.cbClsExtra = 0;<br />
WndClass.cbSize = sizeof(WndClass);<br />
WndClass.cbWndExtra = NULL;<br />
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);<br />
WndClass.hCursor = LoadCursor(g_hInst, IDC_ARROW);<br />
WndClass.hIcon = LoadIcon(g_hInst, IDI_APPLICATION);<br />
WndClass.hIconSm = LoadIcon(g_hInst, IDI_APPLICATION);<br />
WndClass.hInstance = g_hInst;<br />
WndClass.lpfnWndProc = WndProc;<br />
WndClass.lpszClassName = CLASS_NAME;<br />
WndClass.lpszMenuName = NULL;<br />
WndClass.style = CS_HREDRAW|CS_VREDRAW;<br />
<br />
return RegisterClassEx(&WndClass);<br />
}<br />
<br />
BOOL InitiateDD()<br />
{<br />
DDSURFACEDESC2 ddsd;<br />
DDSCAPS2 ddscaps;<br />
<br />
int ddrval = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7,<br />
NULL);<br />
<br />
if(ddrval != DD_OK)<br />
return -1;<br />
<br />
ddrval = g_pDD->SetCooperativeLevel(g_hWnd, DDSCL_EXCLUSIVE|<br />
DDSCL_FULLSCREEN);<br />
<br />
if(ddrval != DD_OK)<br />
return -2;<br />
<br />
ddrval = g_pDD->SetDisplayMode(1024, 768, 32, 0, 0);<br />
<br />
if(ddrval != DD_OK)<br />
return -3;<br />
<br />
ZeroMemory(&ddsd, sizeof(ddsd));<br />
ddsd.dwSize = sizeof(ddsd);<br />
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;<br />
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |<br />
DDSCAPS_COMPLEX;<br />
ddsd.dwBackBufferCount = 1;<br />
<br />
ddrval = g_pDD->CreateSurface(&ddsd, &g_lpDDSPrimary, NULL);<br />
<br />
if(ddrval != DD_OK)<br />
return -4;<br />
<br />
ZeroMemory(&ddscaps, sizeof(ddscaps));<br />
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;<br />
ddrval = g_lpDDSPrimary->GetAttachedSurface(&ddscaps, &g_lpDDSBack);<br />
<br />
if(ddrval != DD_OK)<br />
return -5;<br />
<br />
return true;<br />
}<br />
<br />
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam,<br />
LPARAM lParam)<br />
{<br />
HDC hdc;<br />
PAINTSTRUCT ps;<br />
<br />
switch(iMsg)<br />
{<br />
case WM_PAINT:<br />
{<br />
hdc = BeginPaint(hWnd, &ps);<br />
EndPaint(hWnd, &ps);<br />
}<br />
break;<br />
case WM_QUIT:<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
}<br />
<br />
return DefWindowProc(hWnd, iMsg, wParam, lParam);<br />
}<br />
<br />
void ProcessIdle()<br />
{<br />
HBITMAP hbm;<br />
HDC hdc;<br />
HDC hdc_bmp;<br />
<br />
g_lpDDSPrimary->GetDC(&hdc);<br />
hdc_bmp = CreateCompatibleDC(NULL);<br />
<br />
hbm = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP1));<br />
SelectObject(hdc_bmp,hbm);<br />
BitBlt(hdc,0,0,72,72,hdc_bmp,0,0,SRCCOPY);<br />
}<br />
<br />
void CleanUp()<br />
{<br />
if(g_lpDDSBack)<br />
g_lpDDSBack->Release();<br />
if(g_lpDDSPrimary)<br />
g_lpDDSPrimary->Release();<br />
if(g_pDD)<br />
g_pDD->Release();<br />
}
|
|
|
|
|