struct pieces {
    string ap, bp, cp, dp, ep, fp, gp, hp, ip, jp, lr, rr, lk, rk, lb, rb, q, k;
} b, w;

Code
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C2146: syntax error : missing ';' before identifier 'ap'
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Errors

To me it looks like I'm getting errors because the variables are strings not ints.

Recommended Answers

My guess is that you failed to include <string> header file and/or code the using std::string statment.

Jump to Post

Then you will need to post more code to show us the entire *.cpp file. Otherwise you are just wasting our time.

Jump to Post
#include <string>
#include <iostream>
using namespace std;
struct pieces {
        string ap, bp, cp, dp, ep, fp, gp, hp, ip, jp, lr, rr, lk, rk, lb, rb, q, k;
    } b, w;

int main(){
    b.ap="Hello";
    w.ap=" world.\n";
    cout<<b.ap<<w.ap;
}
/*
 * Output:
 * Hello world.
 */
Jump to Post

It will if you do not have the string header in your struct header file. Please post what you have. Its hard to see your screen from here.

Jump to Post

All 15 Replies

My guess is that you failed to include <string> header file and/or code the using std::string statment.

No, I've already tried that. There is no difference.

Then you will need to post more code to show us the entire *.cpp file. Otherwise you are just wasting our time.

#include <string>
#include <iostream>
using namespace std;
struct pieces {
        string ap, bp, cp, dp, ep, fp, gp, hp, ip, jp, lr, rr, lk, rk, lb, rb, q, k;
    } b, w;

int main(){
    b.ap="Hello";
    w.ap=" world.\n";
    cout<<b.ap<<w.ap;
}
/*
 * Output:
 * Hello world.
 */

I can't see where the problem is. Perhaps you forgot to put the using namespace std; line, and that's why it didnt recognize your struct members.
Or use the std::string instead of the using namespace std;

I have the struct in a header file not main.cpp, will that cause any problems?

It will if you do not have the string header in your struct header file. Please post what you have. Its hard to see your screen from here.

I've barely started on anything.

pieces.h:

#include <string>
struct pieces {
    string ap, bp, cp, dp, ep, fp, gp, hp, ip, jp, lr, rr, lk, rk, lb, rb, q, k;
} b, w;

Chess.cpp:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include "pieces.h"

using namespace std;

bool as_board();

int main(array<System::String ^> ^args)
{
    bool pow = true;
    string white_a, white_b, black_a, black_b;
    string board[65];
    while (pow == true)
    {
        cout << "8 ║" << board[1] << board[2] << board[3] << board[4] << board[5] << board[6] << board[7] << board[8]
             << "\n7 ║" << board[9] << board[10] << board[11] << board[12] << board[13] << board[14] << board[15] << board[16]
             << "\n6 ║" << board[17] << board[18] << board[19] << board[20] << board[21] << board[22] << board[23] << board[24]
             << "\n5 ║" << board[25] << board[26] << board[27] << board[28] << board[29] << board[30] << board[31] << board[32]
             << "\n4 ║" << board[33] << board[34] << board[35] << board[36] << board[37] << board[38] << board[39] << board[40]
             << "\n3 ║" << board[41] << board[42] << board[43] << board[44] << board[45] << board[46] << board[47] << board[48]
             << "\n2 ║" << board[49] << board[50] << board[51] << board[52] << board[53] << board[54] << board[55] << board[56]
             << "\n1 ║" << board[57] << board[58] << board[59] << board[60] << board[61] << board[62] << board[63] << board[64]
             << "\n—╚═══════════════"
             << "\n——a  b  c  d  e  f  g  h";
        cout << "\nWhite: ";
        getline(cin, white_a);
        cout << "To: ";
        getline(cin, white_b);


    }

    return 0;
}

bool as_board()
{

}

In the file pieces.h change string ap ... to std::string ap, ...

Thanks that helped.
As you can tell from the above code I'm trying to build a console type chess game. How would I hold a character such as this: ♘?

If ♘ is the standard ascii character set then look up its numeric value (google will help here) and just assign like you would any other integer.

I'm not entirely sure what they are seeing as google doesn't come up with any results.

google for "ascii table"

They aren't ASCII characters, they're Unicode. See this!
.

It's very unlikely that the characters are going to appear as you want them to, for a console application. You would need a code page which has the appropriate glyphs, mapped to the correct Unicode code points.

While there are Unicode code pages for UTF-7, UTF-8, and UTF-16, I don't know if any of those include the chess characters. I find it unlikely that they do, to be honest. Even if one of them does, the limitations of the console fonts mean that the glyphs are probably going to be virtually unreadable.

How do I go about it though?

Be a part of the DaniWeb community

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