0

So here is the problem. This won't compile. It always gives an error like :
d.cpp:24: error: ‘string’ was not declared in this scope
d.cpp:24: error: expected ‘,’ or ‘;’ before ‘{’ token
Compilatie failed.

#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
int d(int amount, int dots){ // d(X,Y) notation.
		
		/* initialize random seed: */
		srand (time(NULL));
		
		int sum = 0;
		int temp = 0;
		for (int i = 0; i <amount ; i++)
			{
				temp = rand() % dots + 1;
				sum = sum + temp;
			}
		return sum;
	}	
int d(int dots){ 
		int temp = d(1, dots);
		return temp;
	}	

int extract_d(string s){
	int stringsize = s.size();
	int eindwaarden[3] = {0,0,0};
	int waarde = 0;
	int eerstekeer = 0;
		
	for (int count = 0; count < stringsize; count++){
		if(s[count] == 100 || s[count] == 43){
			waarde++;
		}
		else if(eerstekeer == 0){
			eindwaarden[waarde] = s[count] - '0';
			eerstekeer++;
		}
		else {
			eindwaarden[waarde] *= 10;
			eindwaarden[waarde] += s[count] - '0';
		}
	}			
			
	return (d(eindwaarden[0],eindwaarden[1])) +	eindwaarden[2];
}

And i don't really see the problem, i included string right?
Please help....

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by kevinn
1

string resides in std namespace and you have to tell the compiler what namespace it's in. You have several options (use only one of the options listed below)

  1. using namespace std; put that after the include files (least desireable option)
  2. using std::string; put that after the includes
  3. int extract_d(std::string s){ specify the namespace every time you declare an object of type string.

Edited by Ancient Dragon: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.