I'm so stubit guys. You were right i forgot to define the constructor outside the class. It works fine now cheers everyone. Appreciate ur help
antonaras
Posts
-
Template Class Problem - Newbie [modified] -
Template Class Problem - Newbie [modified]Hi toxcct Thanks for helping me. Sorry about my post it was missing all the . U r right i don't define a constructor. Think thats why i get the errors? The default constructor history() won't do the job? Thanks again toxcct
-
Template Class Problem - Newbie [modified]Hi guys I'm trying to figure out how to make a template class History. This class should be able to record history moves.(for any application). e.g. a history of changed in an editor, or a history of URLs in a web browser etc. This is what i came up with so far.
#include < stack > #include < iostream > #include < string > using namespace std; template < typename E > class history { private: //i'm using to stacks to record history stack < E > back_list; stack < E > forward_list; public: history(); void add_entry(const E & entry); E & undo(); E & redo(); bool no_undo(); bool no_redo(); }; template < typename E > void history < E >::add_entry(const E & entry) { back_list.push(entry); while(!forward_list.empty()) { forward_list.pop(); } } template < typename E > E & history < E >::undo() { E entry; if(!back_list.empty()) { entry = back_list.top(); back_list.pop(); forward_list.push(entry); } return(entry); } template < typename E > E & history < E >::redo() { E entry; if(!forward_list.empty()) { entry = forward_list.top(); forward_list.pop(); back_list.push(entry); } return(entry); } template < typename E > bool history < E >::no_undo() { if(back_list.empty()) return(1); else return (0); } template < typename E > bool history < E >::no_redo() { if(forward_list.empty()) return (1); else return (0); } void main() { history <int> his; his.add_entry(2); int out; out = his.undo(); cout< I get no compilation errors but as soon as i try to run it i get: `Linking... history.obj : error LNK2001: unresolved external symbol "public: __thiscall history<int>::history<int>(void)" (??0?$history@H@@QAE@XZ) Debug/history.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. history.exe - 2 error(s), 0 warning(s)` Any ideas of i'm doing wrong? It's the first time i'm using template so i'll appreciate any help. Thank in advance. -- modified at 4:43 Friday 2nd March, 2007
-
string (replace)-newbieThanks a lot Chris Losinger good clear steps thanks a lot
-
string (replace)-newbieHi again guys i have this simple question i have a string that holds some text string text; i want to search the string and replace any ("&nbs" with a space) if i use the string.replace("&nbs"," ") it doesn't work what else do i need to specify for the function to work? Any other ways to do it? Thanks a lot
-
array of char-newbiePersonally i found the answer of Zac very accurate and helpful
-
array of char-newbieyou said::As a side note: you don't need to clear a buffer to overwrite it. It is more efficient to just overwrite it with the new data if your requirements allow for it. but if i overwrite and the new sequence of characters is smaller than the one before some values will still be in the array for example if the the first time i insert 30 characters and the second time only 10 i ll have a problem yes? Thanks for the help Zac Howland
-
array of char-newbiethanks toxcct but if i overwrite and the new sequence of characters is smaller than the one before some values will still be in the array for example if the the first time i insert 30 characters and the second time only 10 i ll have a problem yes? thanks again
-
array of char-newbieHi again guys i have a stupit question lets say i have an array of char char string[50]; i put some characters in it and then i want to erase the content of the array so i can put some other characters in it so anyone knows how i erase all the values from the array? thanks a lot
-
removing spaces-newbieThanks Viorel your answer is very clear and helpful appriciate all the help
-
removing spaces-newbieHey Sarath thanks for the reply can i ask u a couple of questions on strtok? the link u gave me has an example of using strtok char string[] = "A string\tof ,,tokens\nand some more tokens"; char seps[] = " ,\t\n"; char *token; can i use a string instead of char string[]? also can i put any number of deliminars in seps? thanks a lot for the help
-
removing spaces-newbieThanks for the reply Viorel I'm not using MFC so is it possible to use the functions that u mention. also using while(s.Replace(" ", " ") != 0);//i'm going to loose all spaces i need to leave only one. thanks again Viorel
-
removing spaces-newbieHi guys Lets say i have a file with some text in it that the words are seperated with more than one space in between ex. This___________is_______writen______in____a_file____assume______that__underscores____ are________spaces_____how___can_i___remove____them? i want to store this in a string but in this form: This is writen in a file assume that underscores are spaces how can i remove them? any ideas i tried some things but nothing works thank u in advance
-
Frustrated [modified]Hey thanks for the reply yes i also whant to remove newline but spaces in between as well the example is not clear because when i post the message my spaces where removed.
-
Frustrated [modified]thanks for the reply my queue is of type char queuePlainText;
-
Frustrated [modified]Hi again guys i have a strange problem. i'm reading from a file character by character and i'm pushing the characters into a queue like this
do{ c = getc (pFile); plainText.push(c); } while (c != EOF);
so far so good then i copy the content of the queue into a string but i try to remove all unessesary spacesstring text; while (!PlainText.empty()) { if (PlainText.front()!=' ') { Plain_Text+=PlainText.front(); PlainText.pop(); } else if(PlainText.front()==' ') { while(PlainText.front()==' ' && !PlainText.empty() ) { PlainText.pop(); } Plain_Text+=" "; } }
I'm not sure if i made my self clear so i'll give you an example. lets say i have this writen in a fileThis is writen in a text file but with more than one spaces in between the words
i want to copy the contents of this file into the string but in this formThis is writen in a text file but with more than one spaces in between the words
My code doesn't make any changes it lives all the spaces as they where any ideas pls help Thanks a lot -- modified at 6:13 Sunday 11th June, 2006 -
conversion to _bstr_t - newbiethanks Viorel is working fine now thanks for all the help
-
conversion to _bstr_t - newbieThanks Viorel i tried your code but i get lots of compilation errors 'ostrstream' : undeclared identifier syntax error : missing ';' before identifier 'os' 'os' : undeclared identifier and so on what i'm doing wrong i have included string is there anything else i need to include thanks
-
conversion to _bstr_t - newbieHey ThatsAlok i tried your code and it works fine with integers but i have double valField4; TCHAR szStr2[100]; wsprintf(szStr2,"%e",valField4); _bstr_t bstText2(szStr2); printf("%s\n",(LPCSTR)bstText2); the otput for bstText2 that i get is e why does that happen thanks again
-
conversion to _bstr_t - newbieThanks ThatsAlok I'm getting there is almost working how about doubles? Appreciate the help