c++提取字符串
我在字符串中有 26/01/10 09:20:20 MAL BIN BIN275 TSTCB U8L5 O/CR ..N UCOS Operated
我想将第 36 列提取到 60 中,即
BIN275 TSTCB U8L5 O/CR
我想包括的最后一个输出
O/CR
有没有任何简单的解决方案来解决这个问题?已经做到了,但不起作用。
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int main()
{
FILE * pFile;
char mystring [100];
int string_length;
ofstream output;
pFile = fopen ("input.txt" , "r");
output.open("output.txt", ios:: out);
fgets (mystring , 100 , pFile);
puts (mystring);
string_length = strlen(mystring);
int i=36;
while (i < 60)
{
output<<mystring[i];
++i;
}
fclose (pFile);
output.close();
return 0;
}
谢谢
i have 26/01/10 09:20:20 MAL BIN BIN275 TSTCB U8L5 O/CR ..N UCOS Operated
in string
i want to extract column 36 into 60 that is
BIN275 TSTCB U8L5 O/CR
the last output i want to include
O/CR
is there any simple solution to settle this? already make this but not work.
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int main()
{
FILE * pFile;
char mystring [100];
int string_length;
ofstream output;
pFile = fopen ("input.txt" , "r");
output.open("output.txt", ios:: out);
fgets (mystring , 100 , pFile);
puts (mystring);
string_length = strlen(mystring);
int i=36;
while (i < 60)
{
output<<mystring[i];
++i;
}
fclose (pFile);
output.close();
return 0;
}
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的程序基本上可以工作,但您的列号不正确。尝试:
它给了我您指定的结果。
Your program basically works but your column numbers are not correct. Try:
It gives me the result you are specifying.
由于您似乎想使用 C++,我们可以将其编写得稍微优雅一些:
Since you seem to want to use C++, we could write it slightly more elegantly as: