-
April 29th, 2006, 07:25 AM
#1
error C2440: '=' : cannot convert from 'std::string' to 'char *'
I am going to form arrays through string. How to convert from std:string to char.
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
int main()
{
char *str1[5], *str2[5], *test_string[5];
int *input, i;
ifstream in("testdfa.txt"); //open input file
string inbuf;
string old_state, symbol, new_state;
i = 0 ;
while (getline(in, inbuf)) {
istringstream is (inbuf);
is >> old_state;
if (old_state != "FINAL") {
is >> symbol >> new_state;
str1[i] = old_state;
str2[i] = &new_state;
input[i] = symbol;
i += 1;
}
else
{test_string[i] = old_string;
i += 1;}
}
cout<<str1[1];
}
c:\documents and settings\owner\my documents\visual studio 2005\projects\dfa\dfa\dfa.cpp(20) : error C2440: '=' : cannot convert from 'std::string' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:\documents and settings\owner\my documents\visual studio 2005\projects\dfa\dfa\dfa.cpp(21) : error C2440: '=' : cannot convert from 'std::string *__w64 ' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\owner\my documents\visual studio 2005\projects\dfa\dfa\dfa.cpp(22) : error C2440: '=' : cannot convert from 'std::string' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:\documents and settings\owner\my documents\visual studio 2005\projects\dfa\dfa\dfa.cpp(26) : error C2065: 'old_string' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\dfa\dfa\Debug\BuildLog.htm"
dfa - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|