Sorry for asking the topic that asked before... but im still dont know how to use that..

Below is an example create by me.. I hope that someone can tell me which part have to fix ...

This is the header file:

int check_SkipCard (string input)
{
    int SkipCard=0;
    if (input=="skip")
       SkipCard=1;
    return SkipCard;
}

Now is the main .cpp file:

#include <iostream>
#include <cstring>
#include "SkipCard.h"
using namespace std;

main()
{
      int skip;
      int i,j;
      
      for(i=0;i<2;i++){
      for(j=0;j<2;j++){
      cout<<"enter"<<i<<j<<": ";
      cin>>skip;
      if(skip==1)
      j=2;
      else 
      cout<<"no skip dou\n";}}
    
     
      system("pause");
      return EXIT_SUCCESS;
}

The error i get is :
`string' was not declared in this scope, and
expected `,' or `;' before '{' token

There's a few problems to your codes.

Basically, to solve your error, you just have to interchange the below two lines:

#include "SkipCard.h"
using namespace std;

However, I believe the below line will give u an error:

if (input=="skip")

You should use the compare method of string instead.

Finally, it is not a good practice to do your function definition in header file. You should do function declaration in header file and put the function definition in source file instead.

Member Avatar for iamthwee

It should be int main

And the header file you need is #include <string>

cstring is not the one.

I guess its not issue with the Header file. Code is looking good to me. Check what compiler you are using.

im using Dev C++.. the code at main file has no problem.. i try without using header file..
The program can work..

So the problem is i dont know how to change it to using header file

im using Dev C++.. the code at main file has no problem.. i try without using header file..
The program can work..

So the problem is i dont know how to change it to using header file

Please see my solution above.

There's a few problems to your codes.

Basically, to solve your error, you just have to interchange the below two lines:

#include "SkipCard.h"
using namespace std;

what should i change it to??

However, I believe the below line will give u an error:

if (input=="skip")

You should use the compare method of string instead.

this part has no problem.. because i try to compile the program without separate it with header file..
It can be compile, no problem..

what should i change it to??

Switch the position of the two lines stated, as in:

#include <iostream>
#include <cstring>
using namespace std;
#include "SkipCard.h"

Apart from inter changing those lines, also change the way you check string:
if (input=="skip").

Instead of this say:
in (strcmp(input,"skip") == 0).

This is the rite way of checking the strings.

use
if(strcmpi(input,"skip")==0)

instead of
if (input=="skip")

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.