Tag: iostream

iostream链接器错误

我有一些旧的C代码,我想与一些C ++代码结合起来。 以前的C代码包含以下内容: #include #include #include #include “mysql.h” 现在我试图让它像这样使用带有iostream的C ++: #include #include #include #include #include “mysql.h” 但是在编译时我不断收到以下链接器错误: [链接器错误]对`std :: string :: size()const’的未定义引用 [链接器错误]对`std :: string :: operator [](unsigned int)const’的未定义引用 [链接器错误]对`std :: string :: operator [](unsigned int)const’的未定义引用 [链接器错误]对`std :: string :: operator [](unsigned int)const’的未定义引用 [链接器错误]对`std :: ios_base :: Init :: Init()’的未定义引用 [链接器错误]对`std :: ios_base :: Init […]

#include iostream in C?

在C ++中,我们始终将以下内容放在程序的顶部 #include C怎么样?

为什么我需要刷新I / O流才能获得正确的结果?

为什么下面的代码不起作用? 我的意思是,它在控制台输出上显示各种奇怪的字符。 #include char mybuffer[80]; int main() { FILE * pFile; pFile = fopen (“example.txt”,”r+”); if (pFile == NULL) perror (“Error opening file”); else { fputs (“test”,pFile); fgets (mybuffer,80,pFile); puts (mybuffer); fclose (pFile); return 0; } } 但是,下面的代码运行良好。 #include char mybuffer[80]; int main() { FILE * pFile; pFile = fopen (“example.txt”,”r+”); if (pFile == NULL) […]

何时使用printf / scanf vs cout / cin?

我正在使用MinGW的g ++测试我在网上发现的一些片段。 这是C ++编译器……为什么它正确地编译C ….为什么人们交织在一起C和C ++。 具体问题是:使用C和C ++并在g ++下编译是否可以。 如果答案是肯定的,那么我的生活很简单,因为我不需要修改代码。 奇怪的是……让一些C ++工作,特别是在将字符串传递给ifstream构造函数时,它需要一个C类型的字符串…… 我的猜测是,因为C ++有时依赖于C构造,所以可以将两种语言一起编写。 但是,作为一种风格问题,你应该选择cout / cin或printf / scanf 。

在C中逐个字符地读取文件

大家好,我正在用C编写一个BF解释器,我遇到了读文件的问题。 我曾经使用scanf来读取第一个字符串,但是你的BF代码中没有空格或注释。 现在这就是我所拥有的。 char *readFile(char *fileName) { FILE *file; char *code = malloc(1000 * sizeof(char)); file = fopen(fileName, “r”); do { *code++ = (char)fgetc(file); } while(*code != EOF); return code; } 我知道问题出现在我如何将文件中的下一个字符分配给代码指针但是我不确定那是什么。 我的指针知识缺乏,这是本练习的重点。 解释器工作正常,都使用指针,我只是在读取文件时遇到问题。 (我打算稍后只在文件中读取“+ – > <[]。”,但是如果有人有好的方法,那么如果你让我知道的话会很棒!) 提前致谢