草庐IT

border-line-primary

全部标签

c++ - 错误 : expected primary-expression before ‘int’

我正在使用:gcc--版本gcc(Ubuntu4.9.2-0ubuntu1~14.04)4.9.2我正在尝试编译以下程序:#include#includeusingnamespacestd;intmain(){cout但是得到如下错误:g++-fcilkplusCilk_1.cppCilk_1.cpp:Infunction‘intmain()’:Cilk_1.cpp:9:12:error:expectedprimary-expressionbefore‘int’cilk_for(inti=0;i怎么了?谢谢 最佳答案 来自linkC

c++ - 如何区分 LineSegment 类和 Line 类?

我使用两个Point来定义一个Line和一个LineSegment,例如:classPoint{...};classLine{Pointp1,p2;//...};classLineSegment{Pointp1,p2;//...};LineSegment与Line的定义相同,所以我一开始使用了typedefLineLineSegment而不是定义另一个LineSegment类。但是很快,我发现我无法定义函数distance来计算点与线或点与线段之间的距离。classPoint{...};classLine{Pointp1,p2;//...};typedefLineLineSegment

c++ - 使用 -g 选项编译但 "Single stepping until exit from function main, which has no line number information"

我在使用gdb时遇到了一些问题。这是我在一个名为main.cpp的文件中的代码#includevoidmyfunc();intmain(){charmsg[]="HelloWorld!";myfunc();std::cout我使用这个命令来编译这段代码:g++-g-Wallmain.cpp-ofoo接下来,我使用了gdb:$gdbfoo(gdb)startTemporarybreakpoint1at0x80487c3Startingprogram:/home/laptop/workspace/fooTemporarybreakpoint1,0x080487c3inmain()(gdb)

c++ - 嵌套模板 : "expected primary-expression before ' )'"

我正在用C++编写一个Point类并为此使用模板。但是我有一个我不明白的编译错误。我写了一个问题的最小示例:#include#include#includetemplateclassPoint{private:std::arrayvalues;public:templateTget(){returnvalues.at(ROW);};};templateclassField{public:Tprint(std::vector>&vec){for(autoit:vec){Tbla=it.get();//theerrorline27}};};intmain(intargc,char*argv

c++ - 将pugixml的result.offset转换为column/line

我需要为使用pugixml的应用程序提供用户友好的错误报告。我目前正在使用result.offset。有没有办法获取行和列?我可能会处理大型XML文件,如果这有所不同的话。 最佳答案 此功能在pugixml中不容易使用,因为在每次解析时执行此操作的成本相对较高,并且在解析完成后,在一般情况下不可能恢复文件/行信息。这是一个构建偏移量->线映射的片段,您可以在解析失败或出于其他原因需要该信息时使用它;随意调整文件I/O代码以满足您的要求。typedefstd::vectoroffset_data_t;boolbuild_offset_

C++ : Read a file name from the command line and utilize it in my file

如何从命令行读取文件名并在我的C++代码文件中使用它?例如:./cppfileinputFilenameoutputFilename非常感谢任何帮助! 最佳答案 intmain(intargc,char**argv){stringinFile="";stringoutFile="";if(argc==3){inFile=argv[1];outFile=argv[2];}else{cout 关于C++:Readafilenamefromthecommandlineandutilizeiti

c++ - glPolygonMode(GL_FRONT_AND_BACK, GL_LINES) 不工作

我正在尝试以正常填充模式渲染图元,然后将其渲染为线框。渲染代码:glClear(GL_COLOR_BUFFER_BIT);glClearColor(0.9f,0.9f,0.9f,1);//resetmatrixglLoadIdentity();//filldisplaylistglColor3c(150,255,255);glCallList(lDList);//wireframedisplaylistglColor3f(0,0,0);glLineWidth(10);glPolygonMode(GL_FRONT_AND_BACK,GL_LINES);glCallList(lDList)

c++ - C++ 中没有 `while (!my_ifstream.eof()) { getline(my_ifstream, line) }`?

关于thiswebsite,有人写道:while(!myfile.eof()){getline(myfile,line);cout这是错误的,请仔细阅读eof()的文档成员函数。正确的代码是这样的:while(getline(myfile,line))cout这是为什么? 最佳答案 有两个主要原因。@Etienne指出了一个:除了到达文件末尾之外的其他原因,读取可能会失败,在这种情况下,您的第一个版本将进入无限循环。然而,即使没有其他故障,第一个也无法正常工作。eof()不会被设置,直到after由于到达文件末尾而导致读取失败。这意

c++ - C++ : "expected primary-expression before ‘>’ token"中的两个模板

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭7年前。最小工作示例:#includestructPrinter{templatestaticvoidprint(Telem){std::coutstructMain{templatevoidprint(Telem){//Inthiscase,thecompilercouldguessTfromthecontext//Butinmycase,assumethatIneedtospecifyT.printer_t::print(e

c++ - 错误记录 C++ 预处理器宏 __LINE__、__FUNCTION__

我试图将一个简单的错误记录合并到我现有的应用程序中,目前它仅使用cout报告错误所以我希望使用保持类似的界面运算符(operator)。但是我希望它记录该行并运行发生的错误,但我不想输入__LINE__,__FUNCTION__每次我需要登录。有谁知道我可以用来允许__LINE__的技巧吗?要在另一个函数中使用的宏,而不是报告调用行?希望这是有道理的。classmyLogClass{uint8_tlevel;public:booloperator而不是每次都这样myLogClass我只想能够做到:myLogClass 最佳答案 my