#include <iostream>
#include <cstdlib>
#include <string>
#include <ctype.h>
#include <cmath>
#include <functional>
#include <numeric>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
int length = 0;
cout << "Enter a string: ";
string buffer;
char buff[1024];
while (getline(cin, buffer))
{
buffer.erase(remove_if(buffer.begin(), buffer.end(), not1(ptr_fun(isalnum))), buffer.end());
break;
}
length = buffer.length();
int squareNum = ceil(sqrt(length));
strcpy(buff, buffer.c_str());
char** block = new char*[squareNum];
for(int i = 0; i < squareNum; ++i)
block[i] = new char[squareNum];
int count = 0 ;
for (int i = 0 ; i < squareNum ; i++)
{
for (int j = 0 ; j < squareNum ; j++)
{
block[i][j] = buff[count++];
}
}
for (int i = 0 ; i < squareNum ; i++)
{
for (int j = 0 ; j < squareNum ; j++)
{
cout.put(block[j][i]) ;
}
}
return 0;
}
错误:
asst4.cpp: In function ‘int main(int, char**)’: asst4.cpp:30:76: error: no matching function for call to ‘ptr_fun()’ asst4.cpp:30:76: note: candidates are: /usr/include/c++/4.6/bits/stl_function.h:443:5: note: template std::pointer_to_unary_function std::ptr_fun(_Result (*)(_Arg)) /usr/include/c++/4.6/bits/stl_function.h:469:5: note: template std::pointer_to_binary_function std::ptr_fun(_Result (*)(_Arg1, _Arg2)) asst4.cpp:37:29: error: ‘strcpy’ was not declared in this scope
最佳答案
std::strcpy
位于 cstring
header 中,应该包含在内。
std::isalnum
也在 locale
header 中并且 std::ptr_fun
无法选择您需要的一个。您应该手动指定它,例如
std::not1(std::ptr_fun<int, int>(std::isalnum))
或将 std::isalnum
转换为所需的签名
std::not1(std::ptr_fun(static_cast<int(*)(int)>(std::isalnum)))
关于c++ - 为什么这会在 Visual Studio 2012 而不是 UNIX 中编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19630033/