我想将从for-loop读取的值存储到数组中
char A[];
int x;
int y=5;
for( int i=0; int i =1000; i++) {
x = x+y;
// then store/append x as elements of the char array, A.... what is the syntax?
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
c ++ - 字符串上的printf打印出乱码
我想写几个字符串来存档.字符串是
37 1 0 0 0 0
15 1 0 0 0 0
33 1 0 0 0 0
29 1 0 0 0 0
18 1 0 0 0 0
25 1 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
我首先想将每一行存储为字符串数组的元素,然后调用相同的字符串数组并将其元素写入文件.
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;
int writeFile() {
char line[100];
char* fname_r = "someFile_r.txt"
char* fname_w = "someFile_w.txt";
vector<string> vec;
FILE fp_r = fopen(fname_r, "r");
if(fgets(line, 256,fp_r) != NULL) {
vec.push_back(line);
}
FILE …Run Code Online (Sandbox Code Playgroud)