This repository has been archived by the owner on Mar 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCTerminal.mm
67 lines (64 loc) · 1.43 KB
/
LCTerminal.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// NSTerminal.m
// NSTerminal
//
// Created by A on 7/5/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "LCTerminal.h"
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
@implementation LCTerminal
//----Output
+(void)printString:(NSString *)str
{
cout<<[str UTF8String]<<endl;
}
+(void)printStringWithoutNewline:(NSString *)str
{
cout<<[str UTF8String];
}
+(void)printStringWithFormat:(NSString *)format, ...
{
va_list args;
va_start(args, format);
cout << [[[NSString alloc] initWithFormat:format arguments:args] UTF8String] << endl;
va_end(args);
}
+(void)printStringWithoutNewlineWithFormat:(NSString *)format, ...
{
va_list args;
va_start(args, format);
cout << [[[NSString alloc] initWithFormat:format arguments:args] UTF8String] << endl;
va_end(args);
}
//----Input
+(int)readInt
{
int res;
cin>>res;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return res;
}
+(float)readFloat
{
float res;
cin>>res;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return res;
}
+(NSString *)readString
{
string res;
std::getline(std::cin, res);
return [NSString stringWithCString:res.c_str() encoding:NSASCIIStringEncoding];
}
+(NSURL*)readURL
{
string res;
cin>>res;
return [NSURL URLWithString:[NSString stringWithCString:res.c_str() encoding:NSASCIIStringEncoding]];
}
@end