C++ 提取字符串

标签 c++ string extract

我有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/

相关文章:

c++ - 使用静态库的 undefined reference

c++ - 在多个源/头文件中使用 c++ 类时的头文件设置

c++ - Lua:从 c 导出类时的方法和属性

c++ - 如何让 "auto"转换类型

java - 使用嵌套 For 循环比较两个字符串数组

java - 无法在为 Windows 打包的 java 应用程序中提取 jar 文件

php - 使用php从多维数组中获取子数组

java - 翻转字符串中的位

java - 消除String java中的一个char

java - 如何提取网页的主要内容?