okay so I am having an error with the code below and don't really know how to fix it, according to what I've looked up it should be right. I am using g++ on a linux system. (P.S. i'm a newbie )

okay and the error is:
random.cpp: In function ‘int main()’:
random.cpp:9: error: ‘numeric_limits’ was not declared in this scope
random.cpp:9: error: ‘streamsize’ was not declared in this scope
random.cpp:9: error: ‘::max’ has not been declared

here is the code // (i've commented out the line that give me an error.

#include<iostream>

int main(){
std::cout<<"just a random problem"<<std::endl<<"hey I have an Idea enter a number greater than 0, 1 will loop";
int x;
for(;x<=1;){
while(!(std::cin>> x)){
std::cin.clear();
//std::cin.ignore(numeric_limits<streamsize>::max(), '\n' );
}
if (x >= 1){
std::cout<<"you entered"<<x<<std::endl;
}
else if (x<1){
std::cout<<"I said GREATER THAN 0"<<std::endl;
std::cout<<"you entered " << x <<std::endl;
}
else{
        std::cout<<"dude you just made me throw an error"<<std::endl;
        int x = 0;
}
}
}

P.S This is an awesome community and I would like to thank all of you in advance!

Recommended Answers

All 3 Replies

> error: ‘numeric_limits’ was not declared in this scope

#include <limits>

> error: ‘streamsize’ was not declared in this scope

std::streamsize

Thank you that should do the trick!!!

hmm could you give an example of using std::streamsize and adding #inc...<limits> doesn't seem to do much...

Be a part of the DaniWeb community

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