[新手求教]IntelliSense: 有多个 重载函数 "to_string" 实例与参数列表匹配, IntelliSense: 函数调用中的参数太少

柚子学编程 2016-04-23 10:30:03
VS2010平台,代码是从github下载的
代码如下:
#include <iostream>
#include <stdint.h>
#include <fstream>
#include <math.h>
#include "stdio.h"
#include "stdlib.h"
#include <string>
#include <vector>
#include "Vector.h"
#include "LatLng.h"
#include "STLWriter.h"


// g++ elevstl.cpp Vector.cpp LatLng.cpp STLWriter.cpp -o elevstl -std=c++0x

using namespace std;

string tiles[4];

void getTile(float lat, float lng, int index){
string file;
//-------get correct tile-------------------
if(lat>=0){ //Positive is north
file = "N";
}else{
file = "S";
}
file.append( to_string( abs( (int)floor(lat) ) ) );
if(file.length()==2) file.insert(1,"0");
if(lng>=0){ //Positive is east
file.append("E");
}else{
file.append("W");
}
file.append( to_string( abs( (int)floor(lng) ) ) );
if(file.length()==5)file.insert(4,"00");
if(file.length()==6)file.insert(4,"0");

file.append(".hgt");
file.insert(0,"../Terrain2STL/hgt_files/");
tiles[index] = file;
}

错误提示:

请问怎样解决?

...全文
2205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2016-04-23
  • 打赏
  • 举报
回复 1
看了一下发现string头文件里确实有好几个重载的to_string函数 形参类型是long long 或者long double或者unsigned long long 而int都可以隐式转换过去,所以编译器会提示多个重载函数与参数列表匹配,楼主手动强转一下成3个类型中的一个就行了 改成
file.append( to_string( long long(abs( (int)floor(lng) ) )) );
柚子学编程 2016-04-23
  • 打赏
  • 举报
回复
引用 1 楼 qq423399099 的回复:
错误写的很清楚了啊。。。 你传入的参数应该是int吧,有多个to_string能够匹配,此时编译器就懵了,不知道该调用哪个 所以只能不让你通过编译 PS:楼主要么代码多贴一点,起码把重载的to_string函数的声明贴一下
嗯,我明白你的意思了.我开始以为这个是自带的函数,只需引入<string>就行了,我发现原代码里面就没定义to_string函数,在其他文件中也没看到to_string函数.这可怎么办呢..下面是完整代码 #include <iostream> #include <stdint.h> #include <fstream> #include <math.h> #include "stdio.h" #include "stdlib.h" #include <string> #include <vector> #include "Vector.h" #include "LatLng.h" #include "STLWriter.h" // g++ elevstl.cpp Vector.cpp LatLng.cpp STLWriter.cpp -o elevstl -std=c++0x using namespace std; string tiles[4]; void getTile(float lat, float lng, int index){ string file; //-------get correct tile------------------- if(lat>=0){ //Positive is north file = "N"; }else{ file = "S"; } file.append( to_string( abs( (int)floor(lat) ) ) ); if(file.length()==2) file.insert(1,"0"); if(lng>=0){ //Positive is east file.append("E"); }else{ file.append("W"); } file.append( to_string( abs( (int)floor(lng) ) ) ); if(file.length()==5)file.insert(4,"00"); if(file.length()==6)file.insert(4,"0"); file.append(".hgt"); file.insert(0,"../Terrain2STL/hgt_files/"); tiles[index] = file; } int width = 40; int height = 40; float globalLat = 0; vector<float> hList; int main(int argc, char **argv) //lat, long, res, filename, waterDrop, baseHeight { int point; float lat; float lng; int res; int stepSize = 1; int tile_n; int tile_w; int waterDrop = -2; //millimeters int baseHeight = 2; //millimeters //float true_verticalscale = 92.7; //meters/arcsecond at equator //old vertical scale was 23.2 float verticalscale = 92.7; //true_verticalscale gives models that are too flat to be interesting lat = atof(argv[1]); //Latitude of NW corner clog << "Using latitude: " <<lat << "\n"; globalLat = 3.1415926*lat/180; lng = atof(argv[2]); //Longitude of NW corner clog << "Using longitude: " << lng << "\n"; res = atoi(argv[3]); //arcseconds/tick in model if(res%3!=0){ //must be a multiple of 3 clog << "Bad resolution\n"; return 0; } res = res/3; //SRTM data already has a resolution of 3 arcseconds if(res>15){ stepSize = 8; }else if(res>12){ stepSize = 4; }else if(res>9){ stepSize = 2; } clog << "Stepsize: " << stepSize << "\n"; clog << "Using resolution " << res << "\n"; //Arc height = 40*res/stepSize; width = 40*res/stepSize; hList.resize(width*height,0); waterDrop = atoi(argv[4]); baseHeight = atoi(argv[5]); getTile(lat,lng,0); //-------Find starting file index--------------- float n = (lat-floor(lat))*3600; float e = (lng-floor(lng))*3600; int i = 1201-(int)(n/(3)); int j = (int)(e/(3)); int tilesOffsetX = 10000; //how much the secondary x tiles should be offset in x, 10000 means only one tile is used int tilesOffsetY = 10000; //how much the secondary x tiles should be offset in x, 10000 means only one tile is used if(i+height*stepSize>1200){ clog << "Extra tile in y\n"; tilesOffsetY = (1200-i); getTile(lat-1.0,lng,2); } if(j+width*stepSize>1200){ clog << "Extra tile in x\n"; tilesOffsetX = (1200-j); getTile(lat,lng+1.0,1); if(tilesOffsetY!=10000){ getTile(lat-1.0,lng+1.0,3); } } point = j+i*1201; //the file index of the NW corner //------------Open file and read data into array---------------------------- int h; char number [2]; int whichTile; int tileX; int tileY; ifstream file; int openTile = -1;; for(int y = 0; y < height*stepSize; y+=stepSize){ for(int x = 0; x < width*stepSize; x+=stepSize){ tileX = x; tileY = y; if(x<=tilesOffsetX && y<=tilesOffsetY){ //simplify this with bitwise logic? whichTile = 0; point = j+i*1201; } if(x>tilesOffsetX && y<=tilesOffsetY){ whichTile = 1; tileX = x-tilesOffsetX; point = i*1201; } if(x<=tilesOffsetX && y>tilesOffsetY){ whichTile = 2; tileY = y-tilesOffsetY; point = j; } if(x>tilesOffsetX && y>tilesOffsetY){ whichTile = 3; tileX = x-tilesOffsetX; tileY = y-tilesOffsetY; point = 0; } if(openTile!=whichTile){ openTile = whichTile; file.close(); file.open(tiles[whichTile].c_str(),ios::in|ios::binary); } file.seekg((point+tileX+tileY*1201)*2,ios::beg); file.read(number,2); h = number[1]; if(h<0){ h = h+255; } h+= number[0]*256; if(h==0){ h=-waterDrop*verticalscale; } if(h<-1000){ h=-verticalscale*2000*stepSize; } //rotate model to correct orientation //hList.at((height-1-y)*width+x) = h/(verticalscale*res); //cast verticalscale to int for COOl effect! //+baseHeight so that the bottom of the model does not bleed through to the top hList.at((height-1-y/stepSize)*width+x/stepSize) = h/(verticalscale*stepSize)+baseHeight; } } //passing global lat as an xscale - only needed for writeSTLfromArray(hList,width,height,globalLat); return 0; }
小灸舞 2016-04-23
  • 打赏
  • 举报
回复
错误写的很清楚了啊。。。 你传入的参数应该是int吧,有多个to_string能够匹配,此时编译器就懵了,不知道该调用哪个 所以只能不让你通过编译 PS:楼主要么代码多贴一点,起码把重载的to_string函数的声明贴一下
赵4老师 2016-04-23
  • 打赏
  • 举报
回复
模版是语法糖。 语法糖越甜,编译调试查错越苦! 把有限的生命浪费在品尝/品鉴无穷多种的语法糖中,我认为不值当。 使用模版的语法越简洁,语法出错时编译错误提示越费解。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧