#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:在函数'int main(int,char**)'中: asst4.cpp:30:76: 错误: 没有匹配函数调用'ptr_fun()' asst4.cpp:30:76: 注意:候选人是: /usr/include/c++/4.6/bits/stl_function.h:443:5: 注意:模板 std::pointer_to_unary_function std::ptr_fun(_Result (*)(_Arg)) /usr/include/c++/4.6/bits/stl_function.h:469:5: 注意:模板 std::pointer_to_binary_function std::ptr_fun(_Result (*)(_Arg1, _Arg2)) asst4.cpp:37:29:错误:未在此范围内声明“strcpy”