Issue
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.
Solution
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;
}
Answered By - DaaWaan