Saturday, May 22, 2010

Getting a string of character until a tab (C++)?

(This is for a college level programming 2 project, in c++)


In C++ I want to get from a text file (which is already open)


each line is essentially input of


char %26lt;%26lt; string (until a \t) %26lt;%26lt; string %26lt;%26lt; int %26lt;%26lt; int;


I wanted to use the getline command with a buffer for the maximum amount of character, but that's not working.





What command do I use to get a string of strings until a tab '\t'?

Getting a string of character until a tab (C++)?
Get by character instead of get by line.





while (cin.get(ch)!='\t'){





blah;





}





This would get all characters from stdin until a tab.





There are other ways, but I hope this is useful
Reply:You should probably get up to par with the C++ standards, unless your class requires a different standard, such as the old ones.





The new standards use 'std::string', in #include file 'string':





#include %26lt;string%26gt;





using namespace std;





And I think 'std::string' has a 'split' function. Look into it. =)


No comments:

Post a Comment