Skip to content

Instantly share code, notes, and snippets.

@niklasfi
Created May 11, 2011 19:22
Show Gist options
  • Save niklasfi/967109 to your computer and use it in GitHub Desktop.
Save niklasfi/967109 to your computer and use it in GitHub Desktop.
g++ -g -Wall -c ui.cpp
ui.cpp: In function ‘T ui::in(std::string)’:
ui.cpp:13: error: ‘numeric_limits’ is not a member of ‘std’
ui.cpp:13: error: expected primary-expression before ‘>’ token
ui.cpp:13: error: ‘::max’ has not been declared
make: *** [ui.o] Fehler 1
CC = g++
CPPFLAGS = -g -Wall
OBJECTS = ui.o
ifeq ($(shell uname -p | grep -o "64"),64)
ARCH=64
else
ARCH=32
endif
all: ui.exe
%.exe: ${OBJECTS}
${CXX} ${LDFLAGS} -o $@ ${OBJECTS}
%.o: %.cpp %.h
${CXX} ${CPPFLAGS} -c $<
.PHONY : clean
clean :
rm -f *.exe ${OBJECTS}
#include "ui.h"
template <typename T>
T ui::in(std::string message){
T read;
while(true){
std::cout << message << "\n";
std::cin >> read;
if(std::cin.good())return read;
else{
std::cout << "sorry, I did not understand\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
}
int main(){
int foo = ui::in<int>("hallo");
std::cout << foo << "\n";
}
#pragma once
#include <limits>
#include <iostream>
namespace ui{
template <typename T>
T in(std::string message);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment