#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main() {
vector<string> v;
ifstream in ("ttt.txt");
string line;
while (getline(in, line)) {
v.push_back(line);
}
char str[] = v[0].c_str; 这一行会报错cannot convert from '' to 'char []'
cin.get();
}
也试过用char str = v[0].get();把他放在循环里,但是还是有错'get' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
请大家帮忙给看看
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main() {
vector<string> v;
ifstream in ("ttt.txt");
string line;
while (getline(in, line)) {
v.push_back(line);
}
const char *str = v[0].c_str(); //C++中把字符数组按字符串常量对待的 所以注意const
cin.get();
}
也试过用char str = v[0].get();把他放在循环里,但是还是有错'get' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
请大家帮忙给看看
最好用at(i)而不用下标访问,因为at里面有断言,帮助检查错误.