我有一个名为shell脚本的可执行文件:
./lineGraph argv[1] argv[2] ... argv[9]
Run Code Online (Sandbox Code Playgroud)
它创建了类lineGraph的一个实例(这里代码非常简化):
class lineGraph
{
string z[3];
lineGraph(string lumi, string label, char *typeArg, string volume, string axisStyle, string theLine, string z1, string z2, string z3)
{
this->z[0]=z1;
this->z[1]=z2;
this->z[2]=z3;
}
}
public int main(int argc, char* argv[])
{
lineGraph *graphData = new lineGraph(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
};
Run Code Online (Sandbox Code Playgroud)
我得到:
lineGraph.cc:251: error: cannot convert ‘std::string’ to ‘char’ in assignment
lineGraph.cc:252: error: cannot convert ‘std::string’ to ‘char’ in assignment
lineGraph.cc:253: error: cannot convert …Run Code Online (Sandbox Code Playgroud) 我在使用类型时遇到了麻烦char.当我通过构造函数初始化我的ID和Name我的结构时,为什么我收到此错误消息?"expression must be a modifiable lvalue".
struct Staff
{
char ID[8];
char Name[30];
Staff()
{
ID = "";
Name = "";
}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个简单的C程序,其中printf询问你的名字然后用scanf输入它,但输出只给我一个字母的名字.这是我使用的代码:
#include <stdio.h>
main()
{
char cName;
cName = '\0';
printf("What is your name?: ");
scanf("%c", &cName);
printf("Good evening %c", cName);
}
Run Code Online (Sandbox Code Playgroud)
输出:
What is your name?: Michael
Good evening M
Run Code Online (Sandbox Code Playgroud)
当我宣布变量时,我尝试了放置[]和[20]旁边cName,但这也没有用.谁知道我做错了什么?
/* Beginning 2.0 */
#include<stdio.h>
main()
{
printf(" %d signifies the %c of %f",9,'rise',17.0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
大家好
当我编译它时,编译器发出以下警告:
warning: multi-character character constant [-Wmultichar]|
Run Code Online (Sandbox Code Playgroud)
输出只打印e而不是rise.
C中不允许多个字符?
如何打印整个单词(rise)?
请帮帮我.
我有一个程序,我应该将int转换为char进入它
但我不能使用itoa()因为网站的判断不支持它
所以我写了这个:
xt[i]= rmn+'0';
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Runtime error: Illegal file open (/dev/tty)
Run Code Online (Sandbox Code Playgroud)
我应该怎么转换这个?
我的代码是这样的:(对于USACO的palsquare问题)
/*
ID: sa.13781
PROG: palsquare
LANG: C++
*/
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout("palsquare.out");
int tool(char xt[])//CORRECT
{
int p = 0;
while (xt[p] != 0)
p++;
return p;
}
void prt(char xt[])//CORRECT
{
int p = 0;
while (xt[p] != 0)
{
fout << xt[p];
p++;
}
}
void mabna(int a, char xt[], int mab)
{
int ex = 1, tavan = …Run Code Online (Sandbox Code Playgroud) 如何连接i + name + letter + i?
for(int i = 0; i < 10; ++i){
//I need a const char* to pass as a parameter to another function
const char* name = "mki";
//The letter is equal to "A" for the first 2, "B" for the second 3,
//"C" for the following 4 ...
const char* final_string = ???
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用:
std::to_string(i)
Run Code Online (Sandbox Code Playgroud)
但我说错了
对于std,to_string未定义
我正在使用Visual C++.
为什么我能够更改指针中的元素p,而不是指针r?我猜它必须使用指针的属性.
改变p[2]为wGowdbye.更改r崩溃了代码.
p的地址是0x69fee0.
r的地址是0x69fedc.
两者在for循环中都有相同的输出(除了'Goodbye'一词结束后的垃圾数据).
int main()
{
char q[]="Goodbye";
char* p = q;
char* r = "Goodbye";
cout<<"Address of p: "<<&p<<endl;
cout<<"Address of r: "<<&r<<endl;
for(int i = 0; i<10; i++)
{
cout<<"P["<<i<<"]: "<<p[i]<<endl;
cout<<"R["<<i<<"]: "<<r[i]<<endl;
}
p[2]='w';
cout<<p<<endl;
r[2]='w';
cout<<r<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含数字的字符串,.我想,在第一个字符之前删除它.
输入是,1,2,3,4,5,6,7,8,9,10,并且此代码不起作用:
results.replaceFirst(",","");
Run Code Online (Sandbox Code Playgroud) 目标
最后,我想知道为什么C++不支持char letter = "C";但支持char letter = 'C';(注意引号不同).
码
我使用Repl.it作为代码平台.
#include <iostream>
int main()
{
char letter = "C";
std::cout << letter;
}
Run Code Online (Sandbox Code Playgroud)
错误信息
main.cpp:在函数'int main()'中:
main.cpp:5:19:错误:从'const char*'到'char'的无效转换[-fpermissive] char letter ="C";
我的问题是:如何将.txt文件的内容存储char*在C++ 中的命名m_str中?
请注意,我的文件有一个非常明确的格式,我想保留.我不想将这些线合并在一起.我希望第1行保留第1行,第2行是什么,保留第2行.因为最终我将序列化char*并通过网络发送,当节点收到它时,它将反序列化它然后将内容放在一个文件中,并读取原始文件中的行.
谢谢.