我编写了一个涉及使用switch语句的程序......但是在编译时它显示:
错误:跳转到案例标签.
为什么这样做?
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
class contact
{
public:
string name;
int phonenumber;
string address;
contact() {
name= "Noname";
phonenumber= 0;
address= "Noaddress";
}
};
int main() {
contact *d;
d = new contact[200];
string name,add;
int choice,modchoice,t;//Variable for switch statement
int phno,phno1;
int i=0;
int initsize=0, i1=0;//i is declared as a static int variable
bool flag=false,flag_no_blank=false;
//TAKE DATA FROM FILES.....
//We create 3 files names, phone numbers, Address and then …Run Code Online (Sandbox Code Playgroud) 当我编写以下代码并执行它时,编译器说
不推荐使用从字符串常量转换为
char*
int main()
{
char *p;
p=new char[5];
p="how are you";
cout<< p;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这意味着我应该写const char *.
但是当我们将参数传递给main使用时,char* argv[]我们不会写const char* argv[].
为什么?
我正在制作一个javascript函数,我需要确认输入.我写了下面的代码,但即使输入有效值,它给出负值即"其他"部分.有人可以建议一个解决方案吗?
Html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript App</title>
<script type="text/javascript" src="app1.js">
</script>
</head>
<body><h1 id="heading1" style="text-align:center; height:auto; width:auto; font-family:'Arial Black', Gadget, sans-serif">Determinant of a nxn matrix</h1>
<p id="paragraph1" style="font-family:'Arial Black', Gadget, sans-serif"> This program allows you to compute the determinant of a nxn matrix</p>
<p>
Input the order of the matrix
<br />
<input type="text" maxlength="3" name="value" />
<input type="button" value="submit" onclick="verifyorder(value)" />
</p>
<p id="error"></p>
<p id="detspace"></p> …Run Code Online (Sandbox Code Playgroud) 我是c ++的新手,所以这个疑问可能看起来很基本,但我没有得到rand()和srand()之间的区别,你在srand()中的"seed"是什么意思?当我写srand(time(NULL))时,它如何生成随机数,time(NULL)在这里做什么?还有,这是什么?提前致谢
我刚刚通过读取文件中的值从 C++ 矩阵加法教程中找到了这段代码 -
我想问一下#define在这里做什么?它有什么特别之处呢?这与在 main 中单独声明 M 和 N 为 int 或 char 有什么不同?
代码
#include <iostream>
#include <fstream>
using namespace std;
#define M 4
#define N 5
void matrixSum (int P[M][N], int Q[M][N], int R[M][N]);
void matrixSum (int P[M][N], int Q[M][N], int R[M][N]) {
for (int i=0; i<M; i++) // compute C[][]
for (int j=0; j<N; j++)
R[i][j] = P[i][j] + Q[i][j];
}
int main () {
ifstream f;
int A[M][N];
int B[M][N];
int C[M][N];
f.open("values"); // open …Run Code Online (Sandbox Code Playgroud) 在我的考试中,C++中出现了以下问题
码:
int i, n;
int* A
cin >> n;
A = new int[n]
for(int i = 0; i < n; i++) cin >> A[i];
while(i = 0){
cout << A[i] << endl;
i--;
}
}
Run Code Online (Sandbox Code Playgroud)
什么是输出?我认为它应该进入无限循环!
在c ++中,如果我们指定一个指针值NULL,为什么我们不检查是否*p!=NULL相反p!=NULL?
我在教程中找到了这段代码.
int *p = NULL;
char *q = NULL;
// ...
if (p!=NULL) cout << *p;
Run Code Online (Sandbox Code Playgroud)
提前致谢
大家好我对c ++中的字符指针有疑问.每当我们在c ++ char*p ="你好吗?"中创建一个字符指针时,p 应该包含内存位置的地址,其中包含"你好吗"的值.
但是我对一个samle代码和输出感到困惑.为什么要cout<<p退还整个字符串?它应该给出内存地址的值.其次,为什么cout<<*p只给出字符串的第一个字符?提前致谢!码:
#include <iostream>
using namespace std;
int main () {
const char *str = "how are you\n";
int i[]={1,2,3};
cout << str << endl; // << is defined on char *.
cout << i << endl;
cout << *str << endl;
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
how are you
0xbfac1eb0
h
Run Code Online (Sandbox Code Playgroud) 当我遇到以下示例时,我正在读一本关于c ++的书:
#include <iostream>
#include <string>
using namespace std;
int main () {
const char *message = "how do you do\n";
string s(message);
cout << s << " and its size:" << s.size() << endl;
}
Run Code Online (Sandbox Code Playgroud)
我想知道它到底做了什么.我们如何在s(消息)中传递变量inte另一个变量?提前致谢
我读了一本书,int f (int P[2][4])不能接受A[2][3],但B[3][4]很好.这是什么原因?特别是当我们使用指针创建动态分配时,这应该不是问题.谢谢