-
-
Save niklasfi/967109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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