I don't think that really makes any difference, especially since it's just int (a fundamental type) we're talking about, and not something like a class or otherwise.
After all, this compiles:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int foo()
{
return 5;
}
constint bar()
{
return 10;
}
int main()
{
int a = foo(); // Works as expected -- a is 5
constint b = foo(); // Adding 'const'? Whatever
constint c = bar(); // Okay, c is 10
int d = bar(); // Still allowed -- after all, we're just making a copy here
d = 3; // 'd' isn't any different from any other 'int', so no problem with this...
}
I'm using a Const Int, because string arrays require them, throws an error when I use an Int. I am reading a string from a file and need to make it Const Int to use with my string array.
Anyways, that code doesn't seem to use stoi anywhere, it proves nothing.
You should use a std::vector for size-varying arrays.
Size variation isn't just "Start with 8, resize to 9".
Just a "Start with N" requires size variation.
1 2 3 4 5 6 7
int main()
{
int n = (rand()%1024)+1;
std::vector<float> array;
array.resize(n);
array[0] = 0.1f;
}
Ok, well earlier, I was reading on another similar problem I am having, I believe that vector might fix it, but because I couldn't figure out how to create a vector array, I couldn't try it.
How can I use this to loop through reading a file and assign the value of each line to the vector array.
I remember the article said something about .push_back, unsure if that will help you know what I mean.
std::vector<std::string> content;
std::string this_line;
while( read_your_line )
{
content.push_back(this_line);
// adds a this_line at the end of the vector, and increases its size.
}
Ahh, at long last, I have found it, thank you for showing me vector, this is the first time I have seen this! And I believe @Stewbond 's code will help with my other problem! Thanks again!