C++中string的运用如何把文件里string读给对象里的string

小弟新手一枚,初学C++有个问题想请教下各位大虾;
我在文件里存了字符串
然后用infile读出来,然后把这个值赋给我之前定义的对象数组的string name 成员
但是我不知道如何实现,求教

贴出你的代码才知道。如果都是string直接赋值,如果是字符数组,需要一个转换:http://blog.csdn.net/cogbee/article/details/8931838

多谢,已经试过了,同类型可以直接赋的,多谢哈

先搞清楚读文件的过程,从文件读出来的就是字符串,然后再赋值给 String。赋值的过程,是一个最基本的字符串转换过程。

C++中怎样将一个文件的内容读取到string类型的字符串中

 /* fread example: read an entire file */ 
#include <stdio.h> 
#include <stdlib.h> 
int main () { 
FILE * pFile; 
long lSize; 
char * buffer; 
size_t result; 
pFile = fopen ( "myfile.bin" , "rb" ); 
if (pFile==NULL) {fputs ("File error",stderr); exit (1);} 
// obtain file size: 
fseek (pFile , 0 , SEEK_END); 
lSize = ftell (pFile); 
rewind (pFile); 
// allocate memory to contain the whole file: 
buffer = (char*) malloc (sizeof(char)*lSize); 
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);} 
// copy the file into the buffer: 
result = fread (buffer,1,lSize,pFile); 
if (result != lSize) {fputs ("Reading error",stderr); exit (3);} 
/* the whole file is now loaded in the memory buffer. */ 
// terminate 
fclose (pFile); 
free (buffer); 
return 0; 
}

构建函数建一个string 对象,把 char * buffer 内容存入 程序部分,请自己补充:
#include <windows.h>
#include<iostream>
#include <string>
using namespace std;
#include <stdio.h>
// 插入上面程序 .....
// 补充
string sss;
sss.assign(buffer,result);
cout << sss << endl;

用read函数 或者get getline 读取到char数组或指针里 再赋给string类型对象