65,206
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
void main()
{
string str1,str2;
int n;
str1 = "WFW";
cin >> str2 ;
str1 += str2;
n = str1.length();
str1[n] = 0x0a;
n = str1.length();
char c[20];
strcpy(c,str1.c_str());
for (int i = 0;; i++)
{
cout << *(c+i);
if (*(c+i) == 0x0a)
{
cout <<strlen(c)<< endl;
cout << i<< endl;
cout << n<< endl;
break;
}
}
}
#include <iostream>
#include <string>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
void main()
{
string str1,str2;
int n;
str1 = "WFW";
cin >> str2 ;
str1 += str2;
n = str1.length();
//str1[n] = 0x0a; //operator[] 不检测位置的合法性,需要检测,请用 at 函数
str1.at(n)=0x0a;
n = str1.length();
char c[20];
strcpy(c,str1.c_str());
for (int i = 0;; i++)
{
cout << *(c+i);
if (*(c+i) == 0x0a)
{
cout <<strlen(c)<< endl;
cout << i<< endl;
cout << n<< endl;
break;
}
}
}
改成这样你的程序就对头了
多用小脑和手,少用大脑、眼睛和嘴,会更快地学会编程!
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步Debug版对应汇编一行!
单步Debug版对应汇编千行不如单步Release版对应汇编一行!
不会单步Release版对应汇编?在你想单步Release版C/C++代码片断的前面临时加一句DebugBreak();重建所有,然后在IDE中运行。(一般人我不告诉他!
)