我有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;
}
谢谢
最佳答案
您的程序基本上可以运行,但您的列号不正确。尝试:
int i=26;
while (i < 48)
它给了我您指定的结果。
关于C++ 提取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3359050/