Can't get strings to work...

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

Join Date: Nov 2007
Posts: 22
Reputation: pocku is an unknown quantity at this point 
Solved Threads: 0
pocku pocku is offline Offline
Newbie Poster

Can't get strings to work...

 
0
  #1
Oct 15th, 2009
I want to use the string class in my program but I keep getting the following errors:

process.cpp:10: error: 'string' has not been declared
process.cpp:10: error: prototype for 'Process:: Process(int, int, int)'
does not match any in class 'Process'
process.h:14: error: candidates are: Process:: Process(const Process&)
process.h:16: error: Process:: Process(int, char*, int)
process.cpp: In constructor 'Process:: Process(int, int, int)':
process.cpp:14: error: invalid conversion from 'intâ to âchar*'
make: *** [process.o] Error 1

I don't understand why I'm getting this since my code doesn't seem to differ from the examples I found in tutorials too much:

  1. /*
  2.  * process.h
  3.  *
  4.  * Created on: Oct 13, 2009
  5.  * Author: NTUser1
  6.  */
  7.  
  8. #ifndef PROCESS_H_
  9. #define PROCESS_H_
  10.  
  11. #include "thread.h"
  12.  
  13. #include <string>
  14. #include <iostream>
  15.  
  16. using namespace std;
  17.  
  18. class Process : public Thread
  19. {
  20. public:
  21. Process(int at, string process, int bt);
  22.  
  23. int arrivalTime; // arrival time of a process
  24. string name; // process name, e.g., P0, P1, P2
  25. int burstTime; // CPU burst time of a process
  26. int remainTime; // the remaining burst time of a process
  27.  
  28. void run();
  29.  
  30. private:
  31.  
  32. };

  1. /*
  2.  * process.cpp
  3.  *
  4.  * Created on: Oct 13, 2009
  5.  * Author: NTUser1
  6.  */
  7.  
  8. #include "process.h"
  9.  
  10. Process::Process(int at, string process, int bt){
  11.  
  12. arrivalTime = at;
  13. burstTime = bt; //etc for the rest of the vars
  14. name = process;
  15. }
  16.  
  17. void Process::run(){
  18. state = RUNNING;
  19. sleep(burstTime);
  20. stop();
  21. }
Last edited by pocku; Oct 15th, 2009 at 9:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #2
Oct 16th, 2009
what compiler/version are you using ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 381
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 46
jonsca jonsca is offline Offline
Posting Whiz
 
0
  #3
Oct 16th, 2009
I'm not sure which thread library you are using, but even without it you are missing an #endif at the end of your header. I'm not sure if that's the main issue. Are there other errors besides the ones you pasted in?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 22
Reputation: pocku is an unknown quantity at this point 
Solved Threads: 0
pocku pocku is offline Offline
Newbie Poster
 
0
  #4
Oct 16th, 2009
Originally Posted by jonsca View Post
I'm not sure which thread library you are using, but even without it you are missing an #endif at the end of your header. I'm not sure if that's the main issue. Are there other errors besides the ones you pasted in?
I'm using pthread but no, I just forgot to paste in the #endif, it's there in my code. The errors I've posted are the only the ones I'm getting...

Originally Posted by Ancient Dragon View Post
what compiler/version are you using ?
Not too sure as I am doing this on a university computer and I don't know where I can go check at this time.
Last edited by pocku; Oct 16th, 2009 at 12:43 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #5
Oct 16th, 2009
what is the command line to compile something? Or are you using an IDE? Do you know what operating system (e.g. *nix or MS-Windows)?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 22
Reputation: pocku is an unknown quantity at this point 
Solved Threads: 0
pocku pocku is offline Offline
Newbie Poster
 
0
  #6
Oct 16th, 2009
Originally Posted by Ancient Dragon View Post
what is the command line to compile something? Or are you using an IDE? Do you know what operating system (e.g. *nix or MS-Windows)?
I use either g++ or make (to compile multiple files together). I'm programming this on a terminal on linux.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC