Removing stl features from a program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 8
Reputation: jmoran19 is an unknown quantity at this point 
Solved Threads: 0
jmoran19 jmoran19 is offline Offline
Newbie Poster

Removing stl features from a program

 
1
  #1
Nov 5th, 2009
Hi guys, anyone familiar with the Markov Chain Algorithm? I've got an assignment to take the code from a C++ implementation and remove any stl features like deques and maps, but continue to use strings as my main object type. I've based my changes around a C version of the code, which really just needs to be adapted to use C++ strings instead of C char arrays.

The place I'm running into trouble is trying to initialize all my strings with the "non-word" value
  1. "\n"
. Here's the relevant code:

  1. ...
  2. const char NONWORD[] = "\n";
  3. ...
  4. int main(void)
  5. {
  6. int i, nwords = MAXGEN;
  7. string *prefix[NPREF]; // current input prefix
  8.  
  9. srand(time(NULL));
  10. for (int i = 0; i < NPREF; i++)
  11. hashadd(prefix, NONWORD);
  12. hashbuild(prefix, cin);
  13. hashadd(prefix, NONWORD);
  14. hashgenerate(nwords);
  15. return 0;
  16. }
  17. ...
  18. void hashadd(string *prefix[NPREF], string *suffix)
  19. {
  20. State *sp;
  21. sp = lookup(prefix, 1);
  22. addsuffix(sp, suffix);
  23. memmove(prefix, prefix+1, (NPREF-1)*sizeof(prefix[0]));
  24. prefix[NPREF - 1] = suffix;
  25. }
The error I get when I go to compile the code is
"prob3.cpp:104: error: invalid conversion from `const char' to `std::string*'"
pointing to the body of the for loop in main intended to put "\n" in each field of prefix. I've tried replacing all references to NONWORD with
  1. "\n"
but I get the same error. Does anyone have a tip to caste or convert newline as a string?

I have a feeling this is just one of several little hurdles, so if anyone wants to see more of my code to try and find a way around this problem, let me know.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 638
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #2
Nov 5th, 2009
I don't understand why you would want to remove stl features? They make things MUCH easier...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: jmoran19 is an unknown quantity at this point 
Solved Threads: 0
jmoran19 jmoran19 is offline Offline
Newbie Poster
 
0
  #3
Nov 5th, 2009
Originally Posted by daviddoria View Post
I don't understand why you would want to remove stl features? They make things MUCH easier...
It's a homework assignment to prove why it's so useful to have the stl features, while at the same time testing your abilities. Unfortunately, being a transfer student at my school puts you at a disadvantage during some of these more arcane assignments.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 638
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #4
Nov 5th, 2009
Is this what you are looking for?

  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. const char NONWORD[] = "\n";
  7.  
  8. std::string test = NONWORD;
  9. return 0;
  10. }
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC