求教C++语言帝关于输出输入的。。。。。 现在有一个txt文档 里面有四行数字 比如12334226就是我怎么用最简短的语句完成把这四个数字依次赋值给int类型数组a[0]-a[3]呢我之前用的方法都十分的笨拙 我想问下有没有最简单的方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for(int i=0;i<4;i++){ReadString(str);a[i] = atoi(str);} #include <iostream>int main(int argc, char& argv){ if (freopen("test.txt","r",stdin) == NULL) { std::cout << "file not found.\n"; return -1; } int a[4]; std::cin >> a[0]; std::cin >> a[1]; std::cin >> a[2]; std::cin >> a[3]; std::cout << a[0] << std::endl; std::cout << a[1] << std::endl; std::cout << a[2] << std::endl; std::cout << a[3] << std::endl; return 0;} 就是读文件 然后赋值 还想怎么办?CStdioFile m_file;CFileException m_excep;m_file.Open("data.txt", CFile::modeRead, &m_excep);CString str;int j = 0;while (m_file.ReadString(str)){ a[j] = atoi(str); j++;}m_file.Close(); try {#define MAX_COUNT 10 int a[MAX_COUNT] = {0}; int nIndex = 0; CStdioFile file; file.Open(_T("F:\\11.txt"), CFile::modeRead); CString strText(_T("")); while(file.ReadString(strText)) { strText.TrimLeft(_T(" ")); strText.TrimRight(_T(" ")); if(!strText.IsEmpty()) { a[nIndex++%MAX_COUNT] = _ttoi(strText); } } file.Close(); } catch (CException* e) { e->ReportError(); e->Delete(); } ShellExecuteEx(&ShExecInfo)让它启动,再发消息给它的问题. 求:wince下读取文件代码(加急!!!) 如何下载一个压缩文件,并解压缩到指定的目录下?请高人指点,如何能解决!! 初学者问题 关于加密后的字符串的压缩问题。高手请进! 对话框上的Tab改变大小,tab页上的对话框闪烁 聘 VC++高手 一个今年6月才从计算机专业毕业的人想对还在校园里的计算机专业学生说的话。 网络寻址? Windows原始桌面与虚拟桌面 求助:窗体透明 用VisualC++6.0连接Access数据库,中文不能显示
{
ReadString(str);
a[i] = atoi(str);
}
#include <iostream>int main(int argc, char& argv)
{
if (freopen("test.txt","r",stdin) == NULL)
{
std::cout << "file not found.\n";
return -1;
}
int a[4]; std::cin >> a[0];
std::cin >> a[1];
std::cin >> a[2];
std::cin >> a[3]; std::cout << a[0] << std::endl;
std::cout << a[1] << std::endl;
std::cout << a[2] << std::endl;
std::cout << a[3] << std::endl;
return 0;
}
CStdioFile m_file;
CFileException m_excep;
m_file.Open("data.txt", CFile::modeRead, &m_excep);
CString str;
int j = 0;
while (m_file.ReadString(str))
{
a[j] = atoi(str);
j++;
}
m_file.Close();
try
{
#define MAX_COUNT 10
int a[MAX_COUNT] = {0};
int nIndex = 0;
CStdioFile file;
file.Open(_T("F:\\11.txt"), CFile::modeRead);
CString strText(_T(""));
while(file.ReadString(strText))
{
strText.TrimLeft(_T(" "));
strText.TrimRight(_T(" "));
if(!strText.IsEmpty())
{
a[nIndex++%MAX_COUNT] = _ttoi(strText);
}
}
file.Close();
}
catch (CException* e)
{
e->ReportError();
e->Delete();
}