我需要你对错误的看法.
在家里,我用Bloodsheed编写了一个程序并得到了想要的结果.该程序的目的是显示源文件中的行以输出具有特定宽度的文本.源文件无法逐行分析.相反,它应该使用char和string word来读取.
然后我去了uni使用TextPad和Borland提交我的程序:输出是不同的:单词之间的空格和一些行尾字符被忽略.我不明白发生了什么.我花了整整一天的时间没有成功.编译器使用不同的运算符>>来读取字符串吗?看起来在第一种情况下,它在第二种情况下在空格或行尾字符之前停止它丢弃它们.你有关于这个问题的建议吗?
在家里成功的输出是:
Max line length: 40
___Inglis_(1994)_describes_it_thus:
"For_output_of___floating-point_numbers,
the_format_strings_used_by_printf_may
include_%f_or_%e_(or_%g,_which_we_will
ignore).__These_have_much_in_common_with
%i:
____"A_minus_sign_indicates_left
justification,_a_plus_sign_indicates
that_the_converted_value_will_start_with
a_plus_sign_if_it_is_positive,_and_a
minimum_field_width_and/or_a_precision
may_be_specified.
Run Code Online (Sandbox Code Playgroud)
在大学:
Max line length: 40
___Inglis(1994)describesitthus:
"Foroutputof__floating-pointnumbers,the
formatstringsusedbyprintfmayinclude%for
%e(or%g,whichwewillignore)._Thesehave
muchincommonwith%i:
____"Aminussignindicatesleft
justification,aplussignindicatesthatthe
convertedvaluewillstartwithaplussignifit
ispositive,andaminimumfieldwidthand/ora
precisionmaybespecified.
Run Code Online (Sandbox Code Playgroud)
出错的功能:
void Text::display(ofstream & out)
{ ifstream from(infileName.c_str());
if (from.fail())
{ cerr<<infileName<<" not open\n";
exit(1);
}
out<<"Max line length: "<<lineLength<<endl<<endl;
string s, w; //s stands for space, w for word
char l; //l stands for letter
int c=0; //c syands for count
while(true)
{ …Run Code Online (Sandbox Code Playgroud) 我试图创建一个函数来查找数组中的元素数量.为此我找到了以下代码:
#include<iostream>
#include<stdlib>
int no_of_ele(A[]) //function to return size of array
{
return (sizeof(A)/sizeof(A[0]);
}
void main()
{
system("cls");
int arr[5] = {1,2,3,4,5};
cout<<"Number of elements in array are "<<no_of_ele(arr)<<endl;
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
然后,我这样做了:
cout<<"Size of array is "<<sizeof(arr)<<endl;
cout<<"Size of data type is "<<sizeof(arr[0]);
Run Code Online (Sandbox Code Playgroud)
现在我得到绝对正确的大小输出如下:
为什么?
嗨,我已经用 Visual c++ 编写了一个程序,无论出于何种原因,现在我都需要在 turbo c++ 3.0 中运行/编译这个相同的程序。
我已经设法从某个来源获得了编译器,但是当我尝试编译我的代码时出现了很多错误。我已经注释掉了“#include stdafx.h”为ide中的目录和库设置了适当的路径。这些是给我错误的行
#include <list> //Error unable to open include file list
using namespace std; //Declaration syntax error
typedef list<int> itemist; // , expected
bool setPlayerChar(char key); // Type name expected // Declaration missing ;
void generateItemList(piece market[9], itemlist &ilist) // ) expected
bool exit = false; // Undefined symbol 'bool' // statement missing ;
Run Code Online (Sandbox Code Playgroud) 我正在 Windows 7 64 位上使用 DosBox 在 Turbo C++ 中运行图形程序。现在,我想IBM3514在高分辨率模式 ( IBM3514HI) 下使用图形驱动程序。因此,我编写了以下简单程序来测试它:
#include <graphics.h>
#include <iostream.h>
void main() {
int gd = IBM3514, gm = IBM3514HI, e;
initgraph(&gd, &gm, "C:\\TC\\BGI");
if (e = graphresult()) {
cout << grapherrormsg(e);
}
cleardevice();
rectangle(100, 100, 300, 300);
cin.get();
closegraph();
restorecrtmode();
}
Run Code Online (Sandbox Code Playgroud)
现在,程序编译并运行,没有任何错误。但是,该initgraph函数调用不会初始化图形模式。graphresult的返回值为0。因此,没有发生错误。然而,该程序仍然以文本模式运行。闪烁的下划线可见,但未绘制矩形。
我检查了我的C:\TC\BGI文件夹,该IMB3514.BGI文件存在。因此我假设它确实加载了图形驱动程序。然而,我不明白为什么程序不能在图形模式下执行,甚至抛出错误。但是,如果我使用默认设置,它工作得很好:int gd = DETECT, gm;
任何关于为什么我的程序不起作用的解释将不胜感激。请尝试解决此问题。我真的很想在1024x768屏幕上用256颜色画画。
我尝试了很多在我的代码中找到问题,但无法弄清楚为什么输出不正确.我的问题是总结序列2/9 - 5/13 + 8/17 ....这是我的代码我没有得到正确的结果.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,sign=-1;
float a=2,b=9;
clrscr();
cout<<"Enter the number of terms in the series: ";
cin>>n;
float sum = a/b;
for(i=1;i<=n;i++)
{
cout<<a<<"/"<<b<<" "<<sign<<" "<endl;
a=a+3;
b=b+4;
sign= -1*sign;
sum+=sign*(a/b);
}
cout<<"\nThe sum of the series is = "<<sum;
getch();
}
Run Code Online (Sandbox Code Playgroud)
0.660059
请告诉我哪里错了.
什么是c ++的最新编译器.我正在使用Turbo c ++.人们说它很古老.请帮我解决一下这个.
#include<stdio.h>
struct Node
{
};
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个简单的代码以文件名NODE.C保存,这会产生错误:
ERROR NODE.C 5:类型的大小未知或为零
如果我将扩展名从NODE.C更改为NODE.CPP,代码
可以正常工作.有人可以解释为什么会发生这种情况吗?
我用Turbo C++编写了一个程序,然后在那里编译.一切都很成功,程序按预期运行.现在,我想将程序作为exe文件运行.我在一个名为"Source"的单独文件夹中找到了exe文件.但每当我尝试运行它时,我都会收到错误消息:
"此应用程序无法在您的PC上运行.要查找适用于您的PC的版本,请咨询软件发行商."
尽管所有其他软件(如Photoshop)打开正常,但该文件夹中的exe文件都没有工作.
有人可以帮帮我吗?
如果我使用fsin查找实数的sin值。我发现和表达语法错误。我在Dos上使用Turbo C ++ 3.0。
我一直在寻找x87 fpu中的指令列表。我试图谷歌一些信息。并将我在编译器设置上的指令集参考从8087更改为80287。
#include<stdio.h>
#include<math.h>
void main(){
double a = 1.98,val;
asm{
fld a
fsin
fstp val
}
printf("%f", val);
}
Run Code Online (Sandbox Code Playgroud)
表达式sntax错误:fsin