-2

Using Win8.1 system. Using NetBeans IDE for C++ programming because it offers an easy way to make simple windows.

Code:

#include <cstdlib>
#include <iostream>
#include <ctime>
#include <string>

using namespace std;


int main(int argc, char** argv) {

    srand(time(NULL));

    int seed_component0 = rand();

    string Player_name;
    string seed_component1;

    int i = 0;

    cout << "Please, enter your player name: ";
    cin >> Player_name;
    while (i < Player_name.length()){

        seed_component1.append(int(Player_name[i]));
        i++;
    }

    string seed = seed_component0 + seed_component1;

    cout << endl << "The seed we will use is " << seed << endl;


    return 0;
}

That's just the main file, I only created a new project and tried to do that, but when I tried to run it it threw "Unable to resolve identifier length" I also tried with size(). It just doesn't know what that is.

Also I have another error that doesn't affect the program, at least for now; in the include lines, it says"Library file (path) but there is an unresolved #include < stddef.h > in included file (path) wctype.h"

I am using MinGW as the compiler.

Edit: I also wanted to use to_string() and it didn't work either.

  • It's difficult to know what you're trying to achieve. It looks as if you want to convert the characters of the name to integers, convert those integers to decimal string representation and then concatenate them. Is that right? – Richard Hodges Jun 09 '18 at 08:23
  • Yeah, that's what I want, to then use the concatenated string as a seed to **try** and generate content. This is just a practice, as this is the first time I try this. – Emanuel Hongu Jun 09 '18 at 08:43

2 Answers2

0

I tried to use sstream instead of to_string() for conversion. I also replaced your while loop with a for loop. The size() works for me though

Just take a look at http://www.cplusplus.com/articles/D9j2Nwbp/ which is about converting numbers to strings and vice versa

#include <cstdlib>
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>

using namespace std;

string IntToString(int Number)
{
    ostringstream ss;
    ss << Number;
    return ss.str();
}

int main(int argc, char** argv) {

    srand(time(NULL));

    int seed_component0 = rand();

    string Player_name;
    string seed_component1;

    int i = 0;

    cout << "Please, enter your player name: ";
    cin >> Player_name;

    int name_length = Player_name.size();
    for(int i = 0; i < name_length; i++)
    {
        seed_component1 += IntToString(int(Player_name[i]));
    }

    string seed = IntToString(seed_component0) + seed_component1;

    cout << endl << "The seed we will use is " << seed << endl;


    return 0;
}
DaaWaan
  • 561
  • 4
  • 20
  • I literally just copied the string IntToString(int Number) { ostringstream ss; ss << Number; return ss.str(); } part and it already says "Unable to resolve identifier str" in the return ss.str(); line – Emanuel Hongu Jun 09 '18 at 08:23
  • I may have done something wrong when I set up the default compiler or something – Emanuel Hongu Jun 09 '18 at 08:24
  • @EmanuelHongu For Netbeans at least. Go to your project properties and make sure you have your "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors. See https://stackoverflow.com/questions/30686264/erroneous-unable-to-resolve-identifier-in-netbeans – DaaWaan Jun 09 '18 at 08:27
  • Okay now this is strange. I replaced all my code with yours, and set C standard and C++ standard to C11 and C++11, then run the project. It runs perfectly, but for some reason I still says "Unable to resolve identifier size". I mean, it works but it says that at the right so it's contradictory – Emanuel Hongu Jun 09 '18 at 08:33
  • I mean I realy dont care as long as it works, so thank you very much, @HeheBoi !! Have a nice day! – Emanuel Hongu Jun 09 '18 at 08:37
0

Setting both C and C++ to version 11 helped to resolve "unable to resolve length()" issue. Haven't tried to sec C++ v14 or v17 yet

Oleko Dundich
  • 41
  • 1
  • 1
  • 3