我想比较用户输入(文本)和linux下c ++中已声明的字符串(code :: blocks) 我做了这样的事情,但它没有工作
- (void)testCancelation {
NSManagedObjectContext *moc = [self makeMOC];
// Expect that the original block ran to completion and didn't get "interrupted"
XCTestExpectation *origExpectation = [self expectationWithDescription:@"Original block"];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[moc performBlock:^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[origExpectation fulfill];
}];
NSUInteger __block normalBlockCount = 0, cancelBlockCount = 0;
for (int i = 0; i < 100; ++i) {
[moc performBlock:^{
++normalBlockCount;
}];
[moc performCancelableBlock:^{
++cancelBlockCount;
}];
}
[moc cancelPendingBlocks];
// Expect that only blocks in the queue when the cancel request was issued are canceled
XCTestExpectation *doneExpectation = [self expectationWithDescription:@"Cancelable block after cancelation"];
[moc performCancelableBlock:^{
[doneExpectation fulfill];
}];
dispatch_semaphore_signal(semaphore);
[self waitForExpectationsWithTimeout:10 handler:nil];
XCTAssertEqual(100, normalBlockCount);
XCTAssertEqual(0, cancelBlockCount);
}
答案 0 :(得分:2)
您需要使用std::getline()
输入包含空格字符的std::string
:
std::getline(std::cin, test2);
这样做一个简单的比较
if(test1 == test2) {
std::cout << "Done!" << std::endl;
}
应该有用。
您应该注意std::istream& operator>>(std::istream&, std::string&)
只会从输入复制到第一个空格字符(' '
,'\t'
,'\n'
)。