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....

Recommended Answers

All 2 Replies

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.

Thanks! it works:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.