request for member '...' in '...', which is of non-class type 'int'

Pages: 12
I got this error: and idk how to fix it, can you help me? Thanks in advance!
 
request for member 'at' in 'nw', which is of non-class type 'long long int'

for this code:
 
c = nw.at(0); //i want to get 'nw' first character 

where
1
2
int c;
long long int nw;
Last edited on
closed account (48T7M4Gy)
.at() doesn't apply to integers
If you want the first (leftmost) digit in a number you have to convert the number to a string or manipulate the number with some arithmetic.
http://stackoverflow.com/questions/17393757/how-to-retrieve-the-first-digit-of-number-efficiently
Last edited on
You can do what @kemort suggests by writing
char c = std:: to_string (nw)[0]

I wouldn't bother with doing it "efficiently", unless you know that you that this operation is a bottleneck.

if i use
char c = std:: to_string (nw)[0]
it will give me:
1
2
'to_string' is not a member of 'std'| (same line)
unused variable 'c' [-Wunused-variable]| (same line)


if i do:
char c = to_string (nw)[0]
it will give me:
1
2
'to_string' was not declared in this scope| (same line)
unused variable 'c' [-Wunused-variable]| (same line)


i also use at begin of code:
1
2
3
4
5
#include <iostream>
#include <string>

using namespace std;
//... 
Last edited on
to_string is only available in C++11. What compiler do you use ?
code::blocks C++14, i want to use 14, i forget to say
closed account (48T7M4Gy)
http://www.cplusplus.com/reference/string/to_string/
http://en.cppreference.com/w/cpp/string/basic_string/to_string
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main()
{
    int number = 9123456;
    int digit = 0;
    
    std::cout << "    One way: " << std::to_string(number).at(0) << '\n';
    
    while(number > 0)
    {
        digit = number % 10;
        number /= 10;
    }
    std::cout << "Another way: " << digit << '\n';
    
    return 0;
}


    One way: 9
Another way: 9
Program ended with exit code: 0
Last edited on
i have
char c = to_string(nw).at(0);
and i get:
 
'to_string' was not declared in this scope|


i dont want to use the way 2, only way 1, but i still have error's :(, codeblocks 16.01 C++14, if i add std:: it will say its not a member of std, i hope i will fix it succesfully :)
Last edited on
closed account (48T7M4Gy)
Can you run the code I have given you, on your machine?
yes, same error's
line 8 to_string is not a member of std
if i remove std
line 8 to_string was not declared in this scope
Are you sure you're telling the compiler to use C++14 (or C++ 11)? Is that an option you have to turn on in code::blocks?
closed account (48T7M4Gy)
I'm not 100% sure but from memory codeblocks has a fault with the stdio library that has never been fixed and all the nerds who deveolped it are still trying to decide what to do. It's been going on for some time.

This was the reason I scrapped using it a few years ago and will never go back to it. There is a vast array of information about it and one I found a few minutes ago ties in with my previous experience and decision that codeblocks is rubbish.

Probably not what you want to hear but I use Xcode, VStudio and Qt. All are good and work without nonsense workarounds

http://stackoverflow.com/questions/35482921/error-to-string-was-not-declared-in-this-scope-in-codeblocks-16-01
Back to the original problem, do need only the first digit or do you really need all of them?
AFAIK Code blocks uses g++ by default in the back end. It's (at least the current version anyway is) C++14 feature-complete. I don't normally use an IDE, but perhaps OP's compiler is out-dated.

Maybe try following the instructions here:
https://zepix.wordpress.com/2015/07/01/how-to-enable-c14-in-codeblocks/
closed account (48T7M4Gy)
http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-g

This might be worth chasing as there are various claims of fixes and links which post date my fruitless efforts at persisting with CB a few years ago. They might have fixed it, let's hope so. Good luck with it. :)
The g++ compiler didn't add the stoX() and to_string() functions until about version 4.8 of the compiler so if the OP is using a compiler older than that they should stick to the stringstream methods of converting numbers to strings.

@MikeyBoy
Im not sure

@kemort
i dont want to get in any compilers because visual studio is slow (idk why)

@dhayden
i want to be able to get ANY numbers
ex: i want third number of: 99169876393 (1)
i want 6th number of: 841433 (6)

@mbozzi
i do it already but idk why its not working/i not see any changes to my code, same errors

@kemort
still same error's, i think it will never get updated unit C+17 is discovered for those :)

@jib
:/, idk what to say about that, :/
Last edited on
>> Are you sure you're telling the compiler to use C++14 (or C++ 11)?
> Im not sure
show your build command, it may be under "Build log".
something like g++ -std=c++11 foo.cpp -o foo.bin
the `-std' flag tells you which c++ version you are trying to use (if there isn't such flag, you are using c++98)


> from memory codeblocks has a fault with the stdio library that has never been fixed
an IDE should have no business there.


> i want to be able to get ANY numbers digit
¿who is giving you a number? ¿can't you start with a string?


>> The g++ compiler didn't add the stoX() and to_string() functions until about
>> version 4.8 of the compiler
> :/, idk what to say about that, :/
perhaps you should say what is your compiler version
i do-ed again the instruction how to use C++14
g++.exe -Wall -fexceptions -g -pedantic -Wextra -std=c++14 -Iinclude -c

i input a random number
i input the digit number
output the digit value

i use Code::Blocks 16.01, compiler ver: 4.9.2

Last edited on
Pages: 12